Since a recent iOS update somewhere between 16.2 and 16.4.1 a change was introduced that now leads to UICollectionViewController crashing in my app.
The crashes are due to the data source being changed without properly updating the ViewController. However the change is made when the UICollectionView is not displayed which used to be allowed but now causes a crash.
My scenario is this:
UINavigationController
- UICollectionViewController
- UIImageViewController
My data source is a list of images. When a CollectionView item is tapped the UIImageView will be pushed on top of the navigation stack to display this item. From there it is possible to delete the item which removes it from the data source of the CollectionViewController and leads to the crash. This used to be no problem as the CollectionView is lower on the navigation stack and not displayed at the time the alteration occurs. But this has changed in a recent iOS update.
This issue occurs in iOS 16.4.1 and MacOS 13.3.1 (Apple Silicon).
Here is the stack:
Invalid batch updates detected: the number of sections and/or items returned by the data source before and/or after performing the batch updates are inconsistent with the updates. Data source before updates = { 1 section with item counts: [27386] } Data source after updates = { 1 section with item counts: [27385] } Updates = [ Delete item (0 - 27384), Insert item (0 - 27384) ]