Cómo actualizar filas con reloadRowsAtIndexPath
Estoy tratando de eliminar la celda con un botón.
Aquí está la implementación de una célula.
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(0.f, 0.f, 30.f, 30.f);
[btn addTarget:self
action:@selector(btnTouched:)
forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:btn];
cell.tag = indexPath.row;
}
return cell;
}
- (void)btnTouched:(UIButton *)sender
{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:sender.tag inSection:0];
[_myMutableArray removeObjectAtIndex:sender.tag];
[_tableView beginUpdates];
[_tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationLeft];
[_tableView endUpdates];
}
Esto funciona bien hasta que elimine una fila, el botón no se vuelve a cargar, así que después de una eliminación, no elimino el índice bueno. Traté de ponerreloadRowsAtIndexPaths:withRowAnimation:
paravisible indexPath
después de laendUpdates
método y funciona muy bien. Pero la animación de eliminación se volvió fea por la animación reloadRows (incluso si la configuré en NO). Entonces, ¿hay alguna manera de volver a cargar celdas sin reloadCellsAtIndexPath? O eliminar una fila sin usar etiquetas.
Muchas gracias.