In my UICollectionView I use a simple array of custom objects to create and display cells. Sometimes this data changes, and I would like to revive the changes immediately. I decided to do this by tracking all the changes in the second array, distinguishing them and creating a set of move, insert, delete and update operations inside the performBatchUpdates block. Now I understand that it is quite difficult to do all this in one block, because you need to worry about the order of operations with indexes. In fact, the accepted answer to this problem is incorrect (but corrected in the comments).
The documentation seems pretty missing, but it covers one case:
Deletions are processed before being inserted into batch operations. This means indexes for deletions are processed relative to the collection view indices displayed before the batch operation, and indexes for insertions are processed relative to the state indexes after all deletions in the batch operation.
However, the document does not say when transfers are processed. If I call moveItemAtIndexPath and deleteItemsAtIndexPaths in the same performBatchUpdates , should the move indices be in order before or after deletion? What about insertItemsAtIndexPaths ?
Finally, I ran into problems causing reloadItemsAtIndexPaths and moveItemAtIndexPath in the same operation:
Fatal Exception: NSInternalInconsistencyException is trying to delete and reload the same pointer path
Is there a way to do all the operations I want in the same performBatchUpdates ? If so, what update order is processed relative to others? If not, what do people usually do? Reload data after all other operations? Before? I would prefer that all animations happen in one step.
ios objective-c uikit swift uicollectionview
Brent traut
source share