iOS8.4.在设备上不是模拟器.
我得到了这个错误;
Assertion failure in -[UICollectionView _updateWithItems:tentativelyForReordering:], /SourceCache/UIKit/UIKit-3347.44.2/UICollectionView.m:4563
我打电话的时候
NSArray* array_indexPaths = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:1 inSection:0]];
[self.collectionView reloadItemsAtIndexPaths:indexPaths];
Run Code Online (Sandbox Code Playgroud)
我试过把上面的东西放在里面
[self.collectionView performBatchUpdates:^{
没有运气.
有没有其他人经历过这个或者知道为什么会这样?
在UICollectionView中,我试图performBatchUpdates:completion用来执行网格视图的更新.我的数据源数组是self.results.
这是我的代码:
dispatch_sync(dispatch_get_main_queue(), ^{
[self.collectionView performBatchUpdates:^{
int resultsSize = [self.results count];
[self.results addObjectsFromArray:newData];
NSMutableArray *arrayWithIndexPaths = [NSMutableArray array];
if (resultsSize == 0) {
[arrayWithIndexPaths addObject:[NSIndexPath indexPathForRow:0 inSection:0]];
}
else {
for (int i = 0; i < resultsSize; i++) {
[arrayWithIndexPaths addObject:[NSIndexPath indexPathForRow:resultsSize + i inSection:0]];
}
}
for (id obj in self.results)
[self.collectionView insertItemsAtIndexPaths:arrayWithIndexPaths];
} completion:nil];
Run Code Online (Sandbox Code Playgroud)
解释我有什么/我正在做什么:
初始插入集合视图时,此代码运行正常.但是,当我在我的集合视图中添加/插入更多数据时(通过更新self.results并调用它),这会产生以下错误:
*由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'无效更新:第0节中的项目数无效.更新后现有部分中包含的项目数(8)必须等于包含的项目数更新前的那一部分(4),加上或减去从该部分插入或删除的项目数(插入32个,删除0个),加上或减去移入或移出该部分的项目数量(0移入,0搬出去).'
我理解这意味着数据源未正确更新.但是,在查询我的self.results数组时,我看到了新的数据计数.我正在第一行使用addObjectsFromArray.我还存储了旧的结果大小resultsSize.我使用该变量将新添加的索引路径添加到arrayWithIndexPaths.
现在,在添加/插入项目时,我尝试了以下for循环:
for (id obj …