过时数据的断言错误

过时数据的断言错误

本文介绍了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.0I solved the issue the following way:

在函数中

-(NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView

我打电话

[myCollectionView.collectionViewLayout invalidateLayout];

就是这样.

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

09-02 08:12