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

查看:104
本文介绍了陈旧数据的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天全站免登陆