I’m supporting deleting rows in a UIView that includes a tableView:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[self.fetchedResultsController.managedObjectContext
deleteObject:[self.fetchedResultsController
objectAtIndexPath:indexPath]];
NSError *error;
if (![[self.fetchedResultsController managedObjectContext] save:&error]) {
NSLog(@"Unresolved error %@, %@, %@", error, [error userInfo],
[error localizedDescription]);
}
else {NSLog(@"Apparently successful");}
[self.tableView reloadData];
}
}
When I try this out, I get the “Apparently successful” message in the console, but then a SIGABRT in configureCell. It’s as though somewhere the object hasn’t been deleted, and configureCell is trying to present a missing object. (When I re-run the app, though, the record is gone.)
Any thoughts?
You should not have that
[self.tableView reloadData]there when using aNSFetchedResultsController.When you delete an object, the right
NSFetchedResultsControllerDelegatemethod will be called for you, where you should take care of updating your table view.Create an empty Navigation-based Application and check the Use Core Data for Storage checkbox. What you will get is an empty project that does all this correct. It will be a good example.