What is the proper way to chain performBatchUpdate
calls for UICollectionView
such that one update completes before the next begins, to prevent multiple firing at the same time and hence leading to IndexPaths not syncing up (due to deletions mixed in with insertions)
答案 0 :(得分:0)
我不太确定你在这里寻找什么。如果您的意思是如何确保多个线程在执行performBatchUpdate
时不会互相覆盖,则应确保在主线程上调用对performBatchUpdate
的所有调用。 e.g:
DispatchQueue.main.async {
collectionView.performBatchUpdates({
// perform a bunch of updates.
}, completion: { (finished: Bool) in
// anything that needs to happen after the update is completed.
}
}
或者,如果你正在寻找一种在同一个帖子中多次拨打performBatchUpdates
的方法(是的,你有点奇怪,你需要这个,但我有我需要的地方因为我使用的第三方API,因为performBatchUpdates
已完成,您可以尝试将第二个performBatchUpdates
调用放在第一个的完成处理程序中。
self.collectionView.performBatchUpdates({
// perform a bunch of updates.
}, completion: { (finished: Bool) in
self.collectionView.performBatchUpdates({
// perform a bunch of other updates.
}, completion: { (finished: Bool) in
})
})