iOS 10 bug: UICollectionView received layout attributes for a cell with an index path that does not exist

This happened to me when number of cells in collectionView changed. Turns out I was missing invalidateLayout after calling reloadData. After adding it, I haven’t experienced any more crashes. Apple has made some modifications to collectionViews in iOS10. I guess that’s the reason why we are not experiencing same problem on older versions.

Here’s my final code:

[self.collectionView reloadData];
[self.collectionView.collectionViewLayout invalidateLayout];

//Swift 4.2 Version
collectionView.reloadData()
collectionView.collectionViewLayout.invalidateLayout()

Leave a Comment