2010-11-24 7 views
16

J'ai essayé de mettre cela dans différentes parties de mon code, comme à la fin de la méthode commitEditingStyle, mais je n'arrive pas à l'arrêter pour arrêter le mode d'édition. Au fond, je veux en mode d'édition quitter automatiquement quand il n'y a plus de cellules ...Comment désactiver le mode d'édition dans UITableView lorsqu'il n'y a plus de cellules à supprimer?

if ([self.tableView numberOfRowsInSection:0] ==0) 
    { 
     NSLog(@"this triggers, but doesn't stop editing.."); 
     self.tableView.editing = NO; 
     [self.tableView endEditing:YES]; 
    } 

Répondre

36

Que diriez-vous [self setEditing:NO animated:YES]? Je suppose à soi est une instance de UITableViewController.

+0

son fonctionnement bien: merci ... [self.tableView setEditing: NON animé: OUI]; – vijay

5

Si ce n'est pas seulement [self setEditing:NO animated:YES]?

8

De la documentation de pomme:

Note: The data source should not call setEditing:animated: from within its implementation of tableView:commitEditingStyle:forRowAtIndexPath:. If for some reason it must, it should invoke it after a delay by using the performSelector:withObject:afterDelay: method.

Ainsi, appeler cela dans commitEditingStyle n'est pas une grande pratique.

+1

vous l'avez cloué ... – Ans

+1

Demandez-moi comment j'ai appris celui-là. ;-) – tooluser

+0

Comment avez-vous appris cela, @tooluser? :) – Pavan