Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

luke3

macrumors newbie
Original poster
Jun 6, 2012
23
0
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.
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];
            
        }       

        }   
    
    }

Code:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    switch(section){
        case 0:
            return 7;
        case 1:
            return [self.fetchedResultsController.fetchedObjects count];
    }
    return 0;
}
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.