2017-04-10 67 views

回答

0

我不太清楚你在這裏找什麼。如果你的意思是你如何確保在執行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 
     }) 
    })