Question

Sometimes I get this error when trying to delelte a row from the UITableView:

Assertion failure in -[UITableView _endCellAnimationsWithContext:]

and other times it deletes the row with not problems.

Here is my code:

- (void) tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
 forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
     [[self displayedObjects] removeObjectAtIndex:[indexPath row]];


     // Animate deletion
     NSArray *indexPaths = [NSArray arrayWithObject:indexPath];
     [[self tableView] deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];

    }
}
Was it helpful?

Solution

Sounds like your numberOfRowsInSection is returning the wrong Integer sometimes when you enter the editing mode.

OTHER TIPS

Not so sure.. but try this (worked for me once)

First Animate the UITableView deletion, then remove the object from array.

if (editingStyle == UITableViewCellEditingStyleDelete)
    {
     // Animate deletion
     NSArray *indexPaths = [NSArray arrayWithObject:indexPath];
     [[self tableView] deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];

    [[self displayedObjects] removeObjectAtIndex:[indexPath row]];

    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top