Question

I have several UITableViews in an app, and swipe to delete is working fine on all of them. The problem is, when I try to swipe over an empty cell (at the bottom), the app just crashes with:

 *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit/UIKit-1914.84/UITableView.m:833
2012-03-24 16:20:03.158 [22339:707] Exception - attempt to delete row 3 from section 0 which only contains 3 rows before the update - attempt to delete row 3 from section 0 which only contains 3 rows before the update

Neither cellForRowAtIndexPath, commitEditingStyle nor editingStyleForRowAtIndexPath are called before the crash, its like the crash happens before any of my methods have chance to be called.

For reference, I have this in editingStyleForRowAtIndexPath

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    if ((indexPath.row == self.insertIndex && indexPath.section == [self.sections count] -1) || (indexPath.row == 0 && [sections count]==0)) { // last row of section, or only row of only section
        return UITableViewCellEditingStyleInsert;
    } else {
        return UITableViewCellEditingStyleDelete;
    }
}

UPDATE: This is actually a huge problem, as the app is virtually unusable when the tableview scrolls.

Was it helpful?

Solution

It looks like the root cause of this was trying to reload rows in the table view while it was refreshing. There must have been some kind of inconsistent state which resulted, crashing the app every time.

OTHER TIPS

solution:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
//    tableView.isEditing ? NSLog(@"show edit controls"):NSLog(@"don't show edit controls");

    if(tableView.isEditing){
        return NO;
    }else{
        return YES;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top