iOS 10 错误:UICollectionView 接收到具有不存在索引路径的单元格的布局属性 [英] iOS 10 bug: UICollectionView received layout attributes for a cell with an index path that does not exist

查看:39
本文介绍了iOS 10 错误:UICollectionView 接收到具有不存在索引路径的单元格的布局属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在装有 iOS 10 的设备上运行我的应用时出现此错误:

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

UICollectionView 接收到一个单元格的布局属性,其索引路径不存在

在 iOS 8 和 9 中运行良好.我一直在研究,我发现这与使集合视图布局无效有关.我试图实施该解决方案但没有成功,所以我想寻求直接帮助.这是我的层次结构视图:

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

我尝试的是插入

    [self.collectionView.collectionViewLayout invalidateLayout];

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView

两个集合视图.

我还尝试在重新加载数据之前使布局无效,但不起作用...

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

谁能给我一些指示?

推荐答案

collectionView 中的单元格数量发生变化时发生这种情况.原来我在调用 reloadData 后丢失了 invalidateLayout.添加后,我再也没有遇到过崩溃.苹果在 iOS10 中对 collectionViews 做了一些修改.我想这就是我们在旧版本上没有遇到同样问题的原因.

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.

这是我的最终代码:

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

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

这篇关于iOS 10 错误:UICollectionView 接收到具有不存在索引路径的单元格的布局属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆