1
如何連接performBatchUpdate
調用UICollectionView
以使一個更新在下一個開始之前完成,以防止同時發生多次觸發並因此導致IndexPath不同步(由於刪除混入與插入)chaining performBatchUpdates for collectionview
如何連接performBatchUpdate
調用UICollectionView
以使一個更新在下一個開始之前完成,以防止同時發生多次觸發並因此導致IndexPath不同步(由於刪除混入與插入)chaining performBatchUpdates for collectionview
我不太清楚你在這裏找什麼。如果你的意思是你如何確保在執行performBatchUpdate
時多個線程不會互相覆蓋,則應確保在主線程上調用了所有對performBatchUpdate
的調用。例如:
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
})
})