Search code examples
iosiphoneuitableviewanimationcocoa-touch

UITableView row animation duration and completion callback


Is there a way to either specify the duration for UITableView row animations, or to get a callback when the animation completes?

What I would like to do is flash the scroll indicators after the animation completes. Doing the flash before then doesn't do anything. So far the workaround I have is to delay half a second (that seems to be the default animation duration), i.e.:

[self.tableView insertRowsAtIndexPaths:newRows
                      withRowAnimation:UITableViewRowAnimationFade];
[self.tableView performSelector:@selector(flashScrollIndicators)
                     withObject:nil
                     afterDelay:0.5];

Solution

  • Nowadays if you want to do this there is new function starting from iOS 11:

    - (void)performBatchUpdates:(void (^)(void))updates 
                     completion:(void (^)(BOOL finished))completion;
    

    In updates closures you place the same code as in beginUpdates()/endUpdates section. And the completion is executed after all animations.