Si je supprime une ligne de ma table à l'aide d'une animation standard tel que UITableViewRowAnimationFade
le code se bloque avec cette erreur:Suppression ligne de table avec animation en utilisant les données de base
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 1. The number of rows contained in an existing section after the update (4) must be equal to the number of rows contained in that section before the update (4), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted).'
Si je supprime la ligne d'animation la suppression de la ligne/la suppression fonctionne, mais je n'ai plus la transition effrayante d'Apple.
Voici mon code - toute aide est appréciée. Cette méthode de suppression de lignes a fonctionné avant iOS4, vous ne savez pas si quelque chose a changé?
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
// If row is deleted, remove it from the list.
if (editingStyle == UITableViewCellEditingStyleDelete) {
NSIndexPath *path = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
MyItem *myItem = [self.getItemsFetchedResultsController objectAtIndexPath:path];
[dataRepository deleteItem:myItem];
// If I comment this line out the delete works but I no longer have the animation
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView reloadData];
}
}
Dépôt de données:
-(void)deleteItem:(MyItem *)myItem {
[self.managedObjectContext deleteObject:myItem];
[self saveCurrentContext];
}
Merci pour votre réponse, mais je n'ai pas mis en œuvre NSFetchedResultsControllerDelegate - cela ressemble à quelque chose que je devrais regarder dans. J'ai réussi à résoudre mon problème et j'ai posté la réponse – KSoza