I am having trouble deleting an object in an NSMutableSet
using core Data. I am trying to delete a "player" object in the second section of my tableview. I am getting the error;
Invalid update: invalid number of rows in section 1. The number of rows contained in an existing section after the update (6) must be equal to the number of rows contained in that section before the update (6), 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
Solution
Take a look at my code.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
if (indexPath.section==0) {
}else{
_player = [self.fetchedResultsController.fetchedObjects objectAtIndex: indexPath.row];
[self.managedObjectContext deleteObject:_player];
[self performFetch];
[self.managedObjectContext save:nil];
// here the solution to make it works...
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationFade];
}
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
switch(section){
case 0:
return 4;
case 1:
return [self.fetchedResultsController.fetchedObjects count];
}
return 0;
}