UICollectionView断言失败 [英] UICollectionView Assertion failure
问题描述
我在执行 insertItemsAtIndexPaths
时遇到此错误 UICollectionView
I m getting this error on performing insertItemsAtIndexPaths
in 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屋!