Durante el borrado Swype (la mayoría de las líneas importatnt de este método):Eliminar fila en vista de tabla con fetchedResultController
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
Table *deleteRow = [self.fetchedResultsController objectAtIndexPath:indexPath];
[self.managedObjectContext deleteObject:deleteRow];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
Cuando fila borrar me sale este error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 2.
The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (1), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'
Si comento última línea de código ([tableView deleteRowsAtIndexPaths:...]
) todo funciona bien (pero tengo que actualizar la vista para ver que se eliminó la fila).
¿Cómo hacerlo correctamente ..?
EDIT: Considerando responce @Kyr Dunenkoff he añadido:
- (void)controller:(NSFetchedResultsController*)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath*)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath*)newIndexPath
{
UITableView *tableV = [self tableView];
switch(type) {
case NSFetchedResultsChangeDelete:
[tableV deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
- (void)controllerDidChangeContent:(NSFetchedResultsController*)controller
{
[[self tableView] endUpdates];
}
- (void)controllerWillChangeContent:(NSFetchedResultsController*)controller
{
[[self tableView] beginUpdates];
}
Sin embargo, esto no cambió el error estrellarse &. Atm acaba de causar que agregar nuevas filas ya no funcione.
Por favor, verifique mi actualización superior, la corrección no está funcionando como lo implementé (¿puede estar equivocado ...?). ¡Gracias por responder! – Vive
Hm. ¿Qué hay en su método [tableView: numberOfRowsInSection:]? Debería tener algo como 'return [[self.fetchedResultsController fetchedObjects] count];'. –