CATransaction lock block never fires

How does the completion block for this CATransaction never fire?

[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]; 

The tableview animation works, but the completion block is never executed. Apple's documentation says that the block has completed.

+5
source share
1 answer

Oh boy, it was so incomprehensible that I was really amazed, I found a problem.

The cell that was reloaded contains a UIActivityIndicatorView, which works great. When the cell is reloaded, it implicitly redraws the table cell, and the initiating call takes place inside this process in the table cell. Somehow this startAnimating call interferes with the CATransaction termination block.

When I complete the startAnimating call in the dispatch_async block, the problem disappears:

 dispatch_async(dispatch_get_main_queue(), ^{ [self.loadingInd startAnimating]; }); 
+9
source

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


All Articles