Reputation: 711
I am performing batchUpdate.
Here is my code:
if let footerIndex = self.collectionView.feeds.index(forKey: "footer") {
self.collectionView.performBatchUpdates {
self.collectionView.totalSections += 1
self.collectionView.insertSections([footerIndex], animationStyle: .none)
self.collectionView.insertItemsAtIndexPaths([IndexPath.init(row: 0, section: footerIndex)], animationStyle: .none)
}
}
In all earlier iOS versions it works, but iOS 17 it crashes:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid batch updates detected: the number of sections and/or items returned by the data source before and after performing the batch updates are inconsistent with the updates.
Data source before updates = { 47 sections with item counts: [1, 3, 1, 3, 1, 3, 1, 3, 1, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 1, 3, 1, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 1, 3, 1, 3, 1] }
Data source after updates = { 47 sections with item counts: [1, 11, 1, 3, 1, 3, 1, 3, 1, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 1, 3, 1, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 1, 3, 1, 3, 1] }
Updates = [
Insert item (1 - 0),
Insert item (1 - 1),
Insert item (1 - 2),
Insert item (1 - 3),
Insert item (1 - 4),
Insert item (1 - 5),
Insert item (1 - 6),
Insert item (1 - 7),
Insert item (1 - 8),
Insert item (1 - 9),
Insert item (1 - 10)
]
This is the error. Is there any work around for iOS 17?
Upvotes: 0
Views: 2204
Reputation: 36
Normally, the practice should be in three ways:
If you want to update overall collection view then you can use collectionView.reloadData ()
If you want to reload sections of collection view you can use
collectionView.reloadSections ()
If you want to reload the specific cell of collection view you can use collectionView.reloadItems(at: section)
Please always use array to append/delete items and then update collectionView.
Upvotes: 0