2010-12-29 16 views
7

Estoy intentando activar el modo de edición para una UITableView. Cuando hago clic en el botón "Editar", cambia a "Hecho", pero los signos rojos menos redondos no aparecen en la tabla. Estoy publicando a continuación algunos de los métodos de la clase. El delegado de la aplicación creó una Barra de pestañas y las vistas dentro de las pestañas tienen controladores de navegación. todo está hecho en código, poco se hace con los archivos de punta. ¿Qué pasa?Modo de edición de UITableView no funciona

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [ikub.subscriptions count]; 
} 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    int i = [indexPath row]; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"]; 
    } 
    Subscriptions *s = [ikub.subscriptions objectAtIndex:i]; 
    cell.textLabel.text   = [s title]; 
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ artikuj te rinj, %@ artikujt te lexuar", [s new], [s read]]; 
    if (deleteActive) { 
     cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; 
    } else { 
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    } 
    return cell; 
} 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    Subscriptions *s = [ikub.subscriptions objectAtIndex:[indexPath row]]; 
     NSString *address = [[NSString alloc] init]; 
     NSString *type = [NSString stringWithString:[s type]]; 
     if ([type isEqualToString:@"Category"]) { 
      address = [NSString stringWithFormat:@"http://www.ikub.al/Rss.aspx?node=9e26cdb8-dba6-4504-8bb6-29f0753be179~%@", [s code]]; 
     } else if ([type isEqualToString:@"Tag"]) { 
      address = [NSString stringWithFormat:@"http://www.ikub.al/Rss.aspx?tag=%@", [s code]]; 
     } 
     address = [address stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]; 
     SubscriptionStories *ss = [[SubscriptionStories alloc] init]; 
     ss.address = address; 
     ss.title = [s title]; 
     [self.navigationController pushViewController:ss animated:YES]; 
     [ss release]; 
} 
- (void)viewWillAppear:(BOOL)animated { 
    [subscriptionsTable reloadData]; 
} 
- (void)viewDidLoad { 
    refreshButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:nil]; 
    self.navigationItem.leftBarButtonItem = refreshButton; 
    [refreshButton release]; 
    self.navigationItem.rightBarButtonItem = self.editButtonItem; 
    [super viewDidLoad];  
} 
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {  
    return YES; 
} 
+0

bueno olsi favor editar su pregunta, formateando adecuadamente. Es muy difícil entender el código. No hay espacio entre el final y el inicio de los métodos. – iPhoneDev

Respuesta

3

No heredará correctamente.

No obtendrá nada de UIViewController, solo contiene las vistas. Te sugiero que pruebes UITableViewController.

+1

Nada que ver con la herencia si tiene un objeto tableView y el UIViewController es su delegado. –

1

¡Reparado! Tuvo que heredar de UITableViewController no UIViewController.

2

Cuando se escribe el otro método de uitable método de edición de vista gusta esta

-(void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

} 

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { 

    return UITableViewCellEditingStyleDelete; 
} 

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // If row is deleted, remove it from the list. 
    if (editingStyle == UITableViewCellEditingStyleDelete) 
    { 
     rowNumber = indexPath.row; 
     UIActionSheet *registerActionSheet = [[UIActionSheet alloc] initWithTitle:@"Sure You Want To Delete?"delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Yes", nil]; 
     registerActionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque; 
     [registerActionSheet showInView:self.view]; 
     [registerActionSheet release]; 
     // delete your data item here 
     // Animate the deletion from the table. 
     //[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
    } 
} 
17

La herencia no tienen ningún impacto en él.

Puede usar este método, funciona cuando le asigna el botón derecho del navigationController.

- (void)setEditing:(BOOL)editing animated:(BOOL)animated { 
    [super setEditing:editing animated:animated]; 
    [tableView setEditing:editing animated:YES]; 
} 

O puede escribir un método que básicamente cambia el estado de la UITableView como

[tableView setEditing:TRUE]; 

y cuando el botón ha convertido hecho continuación, activar la función de

[tableView setEditing:FALSE]; 
+1

Estoy de acuerdo, votando por arriba, uso UIViewController habitual y funciona bien, en su lugar, necesita: 1. hacer que su controlador sea un delegado de UITableViewDelegate, UITableViewDataSource, 2. implementar - (void) setEditing: (BOOL) edición animada :(BOOL) animado, 3. agregue programáticamente el botón EDITAR - self.navigationItem.rightBarButtonItem = self.editButtonItem – Anonymous

+0

UITableViewController es demasiado limitado, algunas veces es por eso que usamos UIViewController. ¡Buen post! Gracias. –

Cuestiones relacionadas