最近我收到以下错误:
致命异常:NSInternalInconsistencyException无效更新:部分0中的项目数无效。更新(13)之后现有部分中包含的项目数必须等于更新(12)前该部分中包含的项目数,再加上或减去从该部分插入或删除的项目数(已插入0,已删除0),再加上或减去从该部分移入或移出的项目数(移入0,移出0)。
我的tvOS客户端中的以下代码中发生错误:
let removedIndexPaths = removedIndexes.map({ IndexPath(row: $0, section: 0) })
let addedIndexPaths = addedIndexes.map({ IndexPath(row: $0, section: 0) })
let updatedIndexPaths = updatedIndexes.map({ IndexPath(row: $0, section: 0) })
self.collectionView?.performBatchUpdates({
self.collectionView?.deleteItems(at: removedIndexPaths)
self.collectionView?.insertItems(at: addedIndexPaths)
}, completion: { _ in
guard let collectionView = self.collectionView else {
return
}
for indexPath in updatedIndexPaths {
if let myCell = collectionView.cellForItem(at: indexPath) as? MyCollectionViewCell {
let item = self.dataManager.items[indexPath.row]
myCell.updateUI(item)
}
}
let collectionViewLayout = self.collectionViewLayoutForNumberOfItems(self.dataManager.items.count)
if collectionViewLayout.itemSize != self.collectionFlowLayout.itemSize {
collectionView.setCollectionViewLayout(collectionViewLayout, …Run Code Online (Sandbox Code Playgroud)