Hi all,
Here is the dumb question for the day.
I have a coredata backed UITableView. I populate a NSFetchedResultsController
and use that to source the rows and sections etc. All works well.
That is until I go to delete an item from the table.
- (void)tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"commitEditingStyle called");
TheEntity *myEntity = (VideoEntity *) [fetchedResultsController
objectAtIndexPath:indexPath];
NSManagedObjectContext *context = [[self fetchedResultsController]
managedObjectContext];
[context deleteObject:myEntity];
//commit the delete
NSError *saveError = nil;
if (![context save:&saveError]) {
NSLog(@"CoreData save Failure");
}else {
//all good removed from coredata
//now delete from tableView
[self.myTableView deleteRowsAtIndexPaths:[NSArray
arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
Then I get an error like
*** Assertion failure in -[UITableView _endCellAnimationsWithContext:],
/SourceCache/UIKit/UIKit-984.38/UITableView.m:774
*** Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of
rows in section 0. The number of rows contained in an existing section after
the update (3) must be equal to the number of rows contained in that section
before the update (3), plus or minus the number of rows inserted or deleted
from that section (0 inserted, 1 deleted).'
This appears to mean I need to remove it from the fetchedResultsController
before I remove it from the table. So as NSFetchedResultsController has no
remove facility I reload it. Is there a more efficient way of achieving this?
Regards
Damien
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]