I can delete items from the tableView if all of the notes are in one section. As soon as i add items to multiple sections, deleting the note from another section crashes the app with the error:
'Invalid update: invalid number of rows in section 0. The number of rows contained in an
existing section after the update (0) must be equal to the number of rows contained in that
section before the update (1), plus or minus the number of rows inserted or deleted from that
section (0 inserted, 0 deleted) and plus or minus the number of rows moved into or out of
that section (0 moved in, 0 moved out).'
Does anyone know the cause or solution for this?
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[self.tableView beginUpdates];
[self.notes removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationRight ];
[self.data writeToFile:self.path atomically:YES];
[self.tableView endUpdates];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}