UICollectionView 断言失败 [英] UICollectionView Assertion failure

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

问题描述

我在 UICollectionView

断言失败:

-[UICollectionViewData indexPathForItemAtGlobalIndex:], 
/SourceCache/UIKit/UIKit-2372/UICollectionViewData.m:442
2012-09-26 18:12:34.432  
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
reason: 'request for index path for global index 805306367 
when there are only 1 items in the collection view'

我检查过,我的数据源只包含一个元素.关于为什么会发生这种情况的任何见解?如果需要更多信息,我绝对可以提供.

I have checked and my datasource contains only one element. Any insights on why this could happen? If more information is needed I can definitely provide that.

推荐答案

我在将第一个单元格插入集合视图时遇到了同样的问题.我通过更改代码来解决问题,以便调用 UICollectionView

I ran into this very same problem when inserting the first cell into a collection view. I fixed the problem by changing my code so that I call the UICollectionView

- (void)reloadData

插入第一个单元格时的方法,但是

method when inserting the first cell, but

- (void)insertItemsAtIndexPaths:(NSArray *)indexPaths

当插入所有其他单元格时.

when inserting all other cells.

有趣的是,我也遇到了问题

- (void)deleteItemsAtIndexPaths:(NSArray *)indexPaths

删除最后一个单元格时.我做了和以前一样的事情:删除最后一个单元格时只需调用 reloadData.

when deleting the last cell. I did the same thing as before: just call reloadData when deleting the last cell.

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

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