iOS 10 bug: UICollectionView received layout attri

2019-01-10 05:45发布

Running my app in a device with iOS 10 I get this error:

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

In iOS 8 and 9 works fine. I have been researching and I have found that is something related to invalidate the collection view layout. I tried to implement that solution with no success, so I would like to ask for direct help. This is my hierarchy view:

->Table view 
    ->Each cell of table is a custom collection view [GitHub Repo][1]
        ->Each item of collection view has another collection view

What I have tried is to insert

    [self.collectionView.collectionViewLayout invalidateLayout];

In the

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView

of both collection views.

Also I have tried to invalidate layout before doing a reload data, does not work...

Could anyone give me some directions to take?

14条回答
太酷不给撩
2楼-- · 2019-01-10 06:44

In my case, I was changing the NSlayoutConstraint constant

self.collectionViewContacts.collectionViewLayout.invalidateLayout()

            UIView.animate(withDuration: 0.3) {
                self.view.layoutIfNeeded()
            }


            self.collectionViewContacts.reloadData()

solved the issue

查看更多
Emotional °昔
3楼-- · 2019-01-10 06:44

I had this problem as well. In my case there was a custom UICollectionViewLayout applied to the collection view & the problem was that it had stale data for the number of cells that should be displayed. That's definitely something you can check on when you see UICollectionView received layout attributes for a cell with an index path that does not exist

查看更多
登录 后发表回答