Does the UITableView “beginUpdates” and UICollecti

2019-06-14 23:29发布

问题:

I was browsing the documentations, when I started wondering if "beginUpdates" in a UITableView and "performBatchUpdates" in a UICollectionView have the same behavior. If so, is there a reason, that they're called differently, even though they're virtually the same thing?

Thanks!

回答1:

UITableView's beginUpdates must be matched with a call to endUpdates. UICollectionView's performBatchUpdates:completion method does not require you to call back to the collection view when you are doing with the updates, presumably because the block of work that you pass in to update the collection view is wrapped with those calls for you.

UITableView predates blocks being added to Objective-C. I suspect the reason there isn't a similar API for UITableView is that its public API was designed before blocks could be incorporated.