UICollectionView 对陈旧数据的断言错误 [英] UICollectionView assertion error on stale data

查看:25
本文介绍了UICollectionView 对陈旧数据的断言错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试从我的收藏视图中卸载一批图像,然后将它们替换为另一批图像的过程中,我遇到了一个错误,具体取决于原始或后续图像组是多于还是少于预期替换,发生断言错误,内容为:

In the course of trying to unload one batch of images from my collection view and then replace them with another batch, I run into an error where, depending on whether the original or subsequent group of images was more or less than the intended replacement, an assertion error occurs which says:

*** Assertion failure in -[UICollectionViewData validateLayoutInRect:], 
/SourceCache/UIKit_Sim/UIKit-2891.1/UICollectionViewData.m:341
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
reason: 'UICollectionView recieved layout attributes for a cell with an 
index path that does not exist: <NSIndexPath: 0xb141c60> {length = 2, path = 0 - 2}

在这种情况下,现有的图像数列表是 5,新的图像数列表是 2.因此,当它到达第三张图像时 - 发生异常 - 表明 UI CollectionViewDataDelegate 不知道数据流.

In this case the existing list of images count was 5 and the new list of images count was 2. So, when it got to the third image - the exception occurred - indicating that the UI CollectionViewDataDelegate did not know of the change in the data stream.

关于如何确保 UICollectionView 引用新图像的任何建议?当然,我已经调用了reloadData"……

Any suggestions about how to make sure the new images will be referenced by the UICollectionView? Of course I have called 'reloadData'…

谢谢

推荐答案

我遇到了同样的问题.代码在 6.1 下运行,在 7.0 下崩溃我通过以下方式解决了这个问题:

I run in the same problem. Code runs under 6.1 and crashes under 7.0 I solved the issue the following way:

在函数中

-(NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView

我打电话

[myCollectionView.collectionViewLayout invalidateLayout];

仅此而已.

这篇关于UICollectionView 对陈旧数据的断言错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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