Deleting object in NSMutableSet Core Data
Posted
by
Luke
on Stack Overflow
See other posts from Stack Overflow
or by Luke
Published on 2012-07-07T20:45:14Z
Indexed on
2012/07/07
21:15 UTC
Read the original article
Hit count: 145
Hi 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
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 *p = [self.fetchedResultsController.fetchedObjects objectAtIndex: indexPath.section];
[_team removePlayersObject:p];
[_team.players removeObject:p];
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
_managedObjectContext = delegate.managedObjectContext;
[_managedObjectContext deleteObject:p];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationTop];
}
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
switch(section){
case 0:
return 7;
case 1:
return [self.fetchedResultsController.fetchedObjects count];
}
return 0;
}
© Stack Overflow or respective owner