相关疑难解决方法(0)

陈旧数据的UICollectionView断言错误

在尝试从我的集合视图中卸载一批图像然后用另一批替换它们的过程中,我遇到了一个错误,根据原始图像或后续图像组是否多于或少于预期的替换,发生断言错误,其中说:

*** 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}
Run Code Online (Sandbox Code Playgroud)

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

有关如何确保UICollectionView引用新图像的任何建议?当然我叫'reloadData'......

谢谢

uicollectionview ios7

60
推荐指数
5
解决办法
3万
查看次数

UICollectionViewData中的断言失败indexPathForItemAtGlobalIndex

我正在使用performBatchUpdates()来更新我的集合视图,我正在进行完全刷新,即删除其中的任何内容并重新插入所有内容.批量更新是作为附加到()的Observer的一部分完成的.NSMutableArraybingDataItems

cellItems是包含要或将要插入到集合视图中的项的数组.

这是代码:

- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
    cultARunner *_cultARunner = [cultARunner getInstance];
    if ( [[_cultARunner bingDataItems] count] ) {
        [self.collectionView reloadData];
        [[self collectionView] performBatchUpdates: ^{

            int itemSize = [cellItems count];
            NSMutableArray *arrayWithIndexPaths = [NSMutableArray array];

            // first delete the old stuff
            if (itemSize == 0) {
                [arrayWithIndexPaths addObject: [NSIndexPath indexPathForRow: 0 inSection: 0]];
            }
            else {
                for( int i = 0; i < cellItems.count; i++ ) { …
Run Code Online (Sandbox Code Playgroud)

objective-c ios uicollectionview

27
推荐指数
4
解决办法
2万
查看次数

标签 统计

uicollectionview ×2

ios ×1

ios7 ×1

objective-c ×1