I’m trying to figure out what’s going on with my table view. When I delete a row in edit mode it works smoothly, but when the swipe to delete mode goes it breaks down.
I’ve set breakpoints in each of these functions and somehow between comitEditingStyle: atIndexPath and didEndEditingRowAtIndexPath: the indexPath changes from a valid object to nil.
-(void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
editFromSwipe = YES;
[tableView setEditing:YES animated:YES];
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
if(editingStyle == UITableViewCellEditingStyleInsert)
{
[self addNewNoteToGroup:[NSNumber numberWithInt:[indexPath section]]];
}
else if(editingStyle == UITableViewCellEditingStyleDelete && !editFromSwipe)
{
[[noteGroupsList objectAtIndex:[indexPath section]] deleteNoteAtIndex:[indexPath row]];
}
}
-(void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
[notesTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight];
editFromSwipe = NO;
[tableView setEditing:NO animated:YES];
}
The usual way is to call
[notesTable deleteRowsAtIndexPaths:...from the “commit” method, since it’s what’s supposed to delete the row. Possibly there’s an assumption that the row has been deleted, so the old index path is no longer valid, so didEndEditing… has anilindex path.(IIRC the docs also say that you aren’t meant to change the editing state in the “commit”, so you’ll still need didEndEditing.)