I came across something similar when trying to duplicate a collection view in another storyboard.
'UICollectionView received layout attributes for a cell with an index path that does not exist: {length = 2, path = 1 - 0}'
First I seek a quick fix. Tested copies insert various StackOverflow answers.
But I wrote my own layout class. Therefore, I try to debug unnoticed, it may be my implementation is to blame, right? It is established that the numberOfSections method numberOfSections never been called. The collection view assumes that it has only one section.
Then I discovered that the class controller class forgot to match the UICollectionViewDataSource . Although the dataSource was connected in the storyboard, it is likely that the view controller class will be disabled, for example if let ds = dataSource as? UICollectionViewDataSource {ds.numberOfSections...} if let ds = dataSource as? UICollectionViewDataSource {ds.numberOfSections...} , which will fail.
So, I added the UICollectionViewDataSource , and everything works fine. My guess may be inaccurate. But there is a lesson whenever there is a mistake with which you are not familiar, calm down and understand it. The UICollectionView got the layout attributes for a cell with a missing index path , which means exactly what it says. Is not it? Do not try to find a silver bullet, like many of the answers here. They are all great, but your code is the real battleground.
jchnxu Dec 13 '16 at 8:20 2016-12-13 08:20
source share