AVISO: Cualquier pregunta que no cumpla ninguno de estos criterios podrá ser borrada sin previo aviso.

Buenas, tengo un custom buttom en una celda de un UITableView y me gustaría saber como hago para cuando lo presione se borre toda la sección donde se encuentra dicho botón. He probado el siguiente código y no me ha funcionado

[table beginUpdates];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[table deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
[table deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationNone];
[table endUpdates]; 
[table reloadData];

Gracias de antemano

preguntado 17 Abr '12, 16:46

metalsoul89's gravatar image

metalsoul89
38981118

Lamentablemente no te puedo ayudar, ya que tengo un caso parecido al tuyo y no he conseguido resolverlo. Yo estoy intentando implementar algo parecido a lo que sucede cuando activas/desactivas el WIFI en los settings del iPhone. Estaré atento a las posibles respuestas que te dén, a ver si te resuelven las dudas. En el caso de que encuentre antes una solución te la reflejaré lo antes posible.

Un saludo.

(17 Abr '12, 17:57) iQuijano

lo solucione, he aquí el código:

[self.table beginUpdates];
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
    [self.table deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
    [self.table deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationNone];
    [self.table endUpdates];
enlace permanente

respondido 17 Abr '12, 21:21

metalsoul89's gravatar image

metalsoul89
38981118

Gracias por el código, pero no consigo entenderlo, ¿podrías darme una pequeña explicación? A mí me produce el siguiente error:

2012-04-17 22:48:10.905 SCGuardian[1138:f803] Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1912.3/UITableView.m:1030 2012-04-17 22:48:10.906 SCGuardian[1138:f803] Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of sections. The number of sections contained in the table view after the update (4) must be equal to the number of sections contained in the table view before the update (4), plus or minus the number of sections inserted or deleted (0 inserted, 1 deleted).'

También hay que decir que mis celdas y secciones son estáticas...

Gracias de antemano.

Un saludo.

(17 Abr '12, 22:53) iQuijano
Tu respuesta:
Activar/desactivar vista previa