2010-11-24 8 views
16

He intentado poner esto en varias partes de mi código, como al final del método commitEditingStyle, pero no consigo que pare el modo de edición. Básicamente, quiero salir automáticamente del modo de edición cuando no hay más células ...¿Cómo desactivar el modo de edición en UITableView cuando no hay más celdas para eliminar?

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

Respuesta

36

¿Qué tal [self setEditing:NO animated:YES]? Supongo que uno mismo es una instancia de UITableViewController.

+0

funciona bien: gracias ... [self.tableView setEditing: NO animado: YES]; – vijay

5

Si no es solo [self setEditing:NO animated:YES]?

8

A partir de los documentos de manzana:

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.

Por lo tanto, llamar a esto dentro de commitEditingStyle no es una gran práctica.

+1

lo has clavado ... – Ans

+1

Pregúntame cómo lo aprendí. ;-) – tooluser

+0

¿Cómo aprendiste eso, @tooluser? :) – Pavan

Cuestiones relacionadas