Assertion Failure in UICollectionViewData indexPathForItemAtGlobalIndex

后端 未结 8 2046
南旧
南旧 2020-12-15 04:15

I am using performBatchUpdates() to update my collection view, where I am doing a complete refresh, i.e. delete whatever was in it and re-insert everything.

相关标签:
8条回答
  • 2020-12-15 04:53

    I still couldn't figure out how the global index was incremented so much, but I solved my problem by inserting a temporary item in the underlying datasource array i.e. cellItems and calling [self.collectionview reloadData] in viewDidLoad().

    This inserts a placeholder cell temporarily in the collection view until I trigger the actual process using performBatchUpdates().

    0 讨论(0)
  • 2020-12-15 04:56

    I have been having the same problem.

    I have tried a number of variations, but the final one that seems to work is [self.collectionView reloadData], where "self.collectionView"is the name of your collection view.

    I have tried the following methods, straight from the "UICollectionView Class Reference": inserting, moving, and deleting items.

    These were used at first, to "move" the item from one section to another.

    • deleteItemsAtIndexPaths:

    • insertItemsAtIndexPaths:

    Next, I tried moveItemAtIndexPath:toIndexPath:.

    They all produced the following error:

    Assertion failure in -[UICollectionViewData indexPathForItemAtGlobalIndex:], /SourceCache/UIKit_Sim/UIKit-2372/UICollectionViewData.m:442

    So, try the "reloadData" method.

    0 讨论(0)
提交回复
热议问题