问题描述
在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
两个集合视图的
。
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?
推荐答案
当collectionView中的单元格数量发生变化时,我发生了这种情况。原来我在调用reloadData后缺少invalidateLayout。添加后,我没有遇到任何更多的崩溃。 Apple已经对iOS10中的collectionView进行了一些修改。我想这就是我们在旧版本上没有遇到同样问题的原因。
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];
这篇关于iOS 10错误:UICollectionView接收到具有不存在的索引路径的单元格的布局属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!