o9s
is a microblog
home archives search feed blogroll


Animate Table Row Deletion

It’s simple, but there are a lot of small things that can go wrong.

Table Row Delete Animation

[tableView beginUpdates];
[self updateModels];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
                 withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];

Use updateModels to update the table’s data source. The data needs to be valid after the animation. It should not contain the object associated with the row that will be deleted.

Careful, if the model is invalid, your app will crash. If updateModels is outside the updates” block, your app will crash.

If your table view has section headers, good luck. I played around with it. It doesn’t work well. (Tip: the header needs to be removed from the table’s data source after [tableView endUpdates])

Posted on 2018-03-22   #ios     #objc  






← Next post    ·    Previous post →