Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when reloading the collection view data #4

Open
kgn opened this issue Dec 22, 2013 · 2 comments
Open

Error when reloading the collection view data #4

kgn opened this issue Dec 22, 2013 · 2 comments

Comments

@kgn
Copy link

kgn commented Dec 22, 2013

UICollectionView recieved layout attributes for a cell with an index path that does not exist

@aurelienp
Copy link

It seems like for optimization purpose, cached behaviors and visibleIndexPaths are not reseted in prepareLayout. So if your datasource change and you call reloadData, there will be a crash: your error will surely happen when you call reloadData and your previous number of items was "bigger" than the new one.

You could add a reset method to your layout class that empties _animator and _visibleIndexPaths arrays. Then you call [yourCollectionViewLayout reset] just before reloadData each time you want to refresh your collection view... I'm pretty sure it will work but if you have to reload the data often then maybe you should reimplement a layout more appropriate to your needs. Check this post to understand how have been thought the optimizations that cause the problem: http://www.objc.io/issue-5/collection-views-and-uidynamics.html

Hope it helps

@fatuhoku
Copy link

fatuhoku commented May 4, 2014

I get this error when using UICollectionViewFlowLayout. Any ideas how it could have happened?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants