我正在尝试在阅读apple文档后使用以下函数删除collectionView的全部内容。
最终会出现以下错误。
由于未捕获的异常'NSInternalInconsistencyException'而终止应用,原因:'无效更新:无效的节数。更新(0)后集合视图中包含的节数必须等于更新前的集合视图中包含的节数(5),加上或减去插入或删除的节数(插入0,0删除)。“
这是什么意思?或者任何人都可以向我展示一个参考链接,其中包含如何使用一组新数据刷新collectionView内容的示例。
-(void) clearCollectionViewAndDataArray
{
[self.galleryCollectionView performBatchUpdates:^{
[displayDataArray removeAllObjects];
NSLog(@"Is it empty---?%@",displayDataArray);
[self.galleryCollectionView deleteItemsAtIndexPaths:[self createIndexPathArrayEntireCollectionView]];
}
completion:nil ];
}
-(NSMutableArray*) createIndexPathArrayEntireCollectionView
{
NSMutableArray* indexPathArray = [[NSMutableArray alloc] init];
for(int i=0; i < [displayDataArray count]; i++)
{
NSMutableArray* sectionArray=[[NSMutableArray alloc] init];
sectionArray=[displayDataArray objectAtIndex:i];
for(int j=0; j < [sectionArray count]; j++)
{
NSIndexPath* newPath = [NSIndexPath indexPathForRow:j inSection:i];
[indexPathArray addObject: newPath];
}
}
return indexPathArray;
}
使用的NSMutableArray数据是:
(
(
"<SACatalogs: 0x9554750>",
"<SACatalogs: 0x953d9c0>",
"<SACatalogs: 0x953e050>"
),
(
"<SACatalogs: 0x953e6e0>",
"<SACatalogs: 0x953ed70>",
"<SACatalogs: 0x953f420>"
),
(
"<SACatalogs: 0x953fab0>",
"<SACatalogs: 0x9540160>",
"<SACatalogs: 0x95407f0>"
),
(
"<SACatalogs: 0x9540ec0>",
"<SACatalogs: 0x9541530>",
"<SACatalogs: 0x9541be0>"
),
(
"<SACatalogs: 0x9542290>",
"<SACatalogs: 0x9542940>",
"<SACatalogs: 0x9542ff0>"
)
)
使用的索引路径是
"<NSIndexPath 0xa6bb9a0> 2 indexes [0, 0]",
"<NSIndexPath 0xa648bc0> 2 indexes [0, 1]",
"<NSIndexPath 0xa6dcdc0> 2 indexes [0, 2]",
"<NSIndexPath 0xa6c7d00> 2 indexes [1, 0]",
"<NSIndexPath 0xa6c91c0> 2 indexes [1, 1]",
"<NSIndexPath 0xa6f6100> 2 indexes [1, 2]",
"<NSIndexPath 0xa6490d0> 2 indexes [2, 0]",
"<NSIndexPath 0xa6a93b0> 2 indexes [2, 1]",
"<NSIndexPath 0xa6d08b0> 2 indexes [2, 2]",
"<NSIndexPath 0xa64ddb0> 2 indexes [3, 0]",
"<NSIndexPath 0xa6f7380> 2 indexes [3, 1]",
"<NSIndexPath 0xa6c1c90> 2 indexes [3, 2]",
"<NSIndexPath 0xa6e45f0> 2 indexes [4, 0]",
"<NSIndexPath 0xa6bf840> 2 indexes [4, 1]",
"<NSIndexPath 0xa6a03f0> 2 indexes [4, 2]"
}
先谢谢
答案 0 :(得分:0)
似乎首先从displayDataArray
删除所有对象,然后计算
来自indexPathArray
的{{1}}。因此displayDataArray
将为空
和
indexPathArray
没有。将订单更改为
[self.galleryCollectionView deleteItemsAtIndexPaths:[self createIndexPathArrayEntireCollectionView]];
可以解决问题。但正如评论中所提到的,你可以打电话
如果所有集合视图项已被删除,则[self.galleryCollectionView deleteItemsAtIndexPaths:[self createIndexPathArrayEntireCollectionView]];
[displayDataArray removeAllObjects];
。