我想從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 –