8
 [self.tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)] withRowAnimation:UITableViewRowAnimationLeft];
 [self.tableView reloadRowsAtIndexPaths:@[ [NSIndexPath indexPathForItem:1 inSection:1]] withRowAnimation:UITableViewRowAnimationRight];

In the above code how do I make the second line execute after the animation from the first line has completed?

I tried this...

[self.tableView beginUpdates];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)] withRowAnimation:UITableViewRowAnimationLeft];
{
    [self.tableView beginUpdates];
    [self.tableView reloadRowsAtIndexPaths:@[ [NSIndexPath indexPathForItem:1 inSection:1]] withRowAnimation:UITableViewRowAnimationRight];
    [self.tableView endUpdates];
}
[self.tableView endUpdates];

and this...

[self.tableView beginUpdates];
{
    [self.tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)] withRowAnimation:UITableViewRowAnimationLeft];
}
[self.tableView endUpdates];
[self.tableView beginUpdates];
{
    [self.tableView reloadRowsAtIndexPaths:@[ [NSIndexPath indexPathForItem:1 inSection:1]] withRowAnimation:UITableViewRowAnimationRight];
}

...but either way the animations are clearly happening at the same time (and really apparent when slow animations is on).

Murray Sagal
  • 8,454
  • 4
  • 47
  • 48
  • 1
    You can take help from this http://stackoverflow.com/questions/3832474/uitableview-row-animation-duration-and-completion-callback – Iducool Apr 28 '13 at 11:31
  • It would appear this is how it is done: http://stackoverflow.com/questions/2802146/callback-for-uitableview-animations – Dev2rights Apr 28 '13 at 12:54

1 Answers1

26

Thank you Iducool for pointing me to the other question.

This worked...

[CATransaction begin];
[CATransaction setCompletionBlock:^{
    [self.tableView reloadRowsAtIndexPaths:@[ [NSIndexPath indexPathForItem:1 inSection:1]] withRowAnimation:UITableViewRowAnimationRight];
}];

[self.tableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)] withRowAnimation:UITableViewRowAnimationLeft];

[CATransaction commit];

I didn't seem to require UITableView's beginUpdates and endUpdates.

Murray Sagal
  • 8,454
  • 4
  • 47
  • 48
  • 4
    If the loaded cell contains a `UIActivityIndicatorView` then the completion block is never called. – markturnip Mar 11 '14 at 01:19
  • 4
    didn't work for me on iOS 9 with reload/insertSections – tettoffensive Oct 09 '15 at 23:25
  • @markturnip Did you ever find a solution to this if you have an activity indicator view in the cell? I asked this here. http://stackoverflow.com/questions/39672868/reloading-table-view-cells-with-an-activity-indicator-view – Berry Blue Sep 24 '16 at 23:31