How to wait for the completion of the embedded animation UITableView?

[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 to execute the second line after completing the animation from the first line?

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 in any case, the animation clearly happens at the same time (and is really obvious with slow animation).

+6
source share
1 answer

Thanks to Iducool for pointing me to another question.

It 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 did not need the UITableView beginUpdates and endUpdates .

+22
source

Source: https://habr.com/ru/post/943812/


All Articles