I am displaying data from CoreData
in a UITableView
using NSFetchedResultsController
as the container for the NSManagedObjects
. The code for deleting a row works well, but my implementation strikes me as less than elegant. Is there a better way?
The code below illustrates the deletion event:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[myContext deleteObject:[fetchedResultsController objectAtIndexPath:indexPath]];
if (![myContext save:&error]) {
// Error handling
}
fetchedResultsController = nil;
if (![[self getFetchedResultController] performFetch:&error]) {
// Error handling
}
[tableView reloadData];
}
}
I set the fetchedResultsController
to nil
and perform another fetch to update the new contents.
What concerns me is that I have seen references on various forums hinting that a change in the context should automatically engender changes in the fetchedResultsController and perhaps this second fetch is unnecessary. I have not implemented sections at this point.
Another concern is that the code simply makes the row disappear without any animation.
Could some slick animation be introduced?