我如何等待UITableView内置动画完成?

Mur*_*gal 7 objective-c uitableview ios

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

在上面的代码中,如何在第一行的动画完成后执行第二行?

我试过这个......

[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];
Run Code Online (Sandbox Code Playgroud)

还有这个...

[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];
}
Run Code Online (Sandbox Code Playgroud)

......但无论哪种方式,动画都是在同一时间发生的(当动画速度很慢时,动画真的很明显).

Mur*_*gal 24

谢谢Iducool指点我另一个问题.

这有效......

[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];
Run Code Online (Sandbox Code Playgroud)

我似乎没有需要UITableViewbeginUpdatesendUpdates.

  • 如果加载的单元格包含"UIActivityIndi​​catorView",则永远不会调用完成块. (4认同)
  • 在iOS 9上使用reload/insertSections对我不起作用 (4认同)