CATransaction完成块永远不会触发

时间:2014-12-14 14:07:11

标签: ios catransaction

为什么这个CATransaction的完成块永远不会触发?

[CATransaction begin];
[CATransaction setCompletionBlock:^{
    // table animation has finished
    NSLog(@"why does this section never execute?");
}];
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:self.currentFeedItems.count inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
[CATransaction commit];

tableview动画有效,但永远不会执行完成块。 Apple文档说保证完成块可以执行。

1 个答案:

答案 0 :(得分:10)

噢,小伙子,这太晦涩了我真的很惊讶我发现了这个问题。

正在重新加载的单元格包含一个UIActivityIndi​​catorView,它工作正常。当单元格重新加载时,它会隐式重绘表格单元格,并且在表格单元格中的该过程中会发生startAnimating调用。不知何故,startAnimating调用会干扰CATransaction完成块。

当我将startAnimating调用包装在dispatch_async块中时,问题就消失了:

dispatch_async(dispatch_get_main_queue(), ^{
    [self.loadingInd startAnimating];
});
相关问题