我想从UICollectionView中删除单元格。虽然删除单元格,我得到NSInternalInconsistencyException从collectionView中删除单元格
***终止应用程序由于未捕获的异常“NSInternalInconsistencyException”,理由是:“无效的更新:在第0包含在现有的部分更新后的项目数项目数无效(5)必须等于更新之前该部分中包含的项目数(5),加上或减去从该部分插入或删除的项目数(插入0个,删除1个),加上或减去项目数移入或移出该部分(0移入,0移出)。'错误。
这里是我的代码:
[self.imgArray removeObjectAtIndex:indexForDelete];
[self.collectionView performBatchUpdates:^{
NSIndexPath *indexPath =[NSIndexPath indexPathForItem:indexForDelete inSection:0];
[self.collectionView deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
} completion:^(BOOL finished) {
}];
我追加一个虚拟池时,我的数组数不为5 这里是numberOfItems代码numberOfItemsInSection
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
if(self.imgArray.count == 5)
{
return self.imgArray.count ;
}
else
{
return self.imgArray.count + 1;
}
}
我发现很多的解决方案谷歌和Stackoverflow,但没有发现帮助完整的我。
你并不需要一个单一的删除'performBatchUpdates'。摆脱这一点,只是保持块内的两条线。 – Paulw11
你可以显示你的'numberOfItemsInSection'方法吗? – Paulw11
看到我更新的问题。 @ Paulw11 –