所有错误文本:
无效更新:第0节中的无效项数。更新(0)之后现有节中包含的项数必须等于更新(1)前该节中包含的项数,再加上或减去从该部分插入或删除的项目数(插入0,删除0),再加上或减去从该部分移入或移出的项目数(移入0,移出0)。
发生此错误的方法(仅在删除时,从集合中创建或更新项目时没有错误),发生此错误仅在iOS12,iOS13和>没错。
var cards: [Card] = []
item = self.cards[itemIndex]
self.collectionView.performBatchUpdates({
// here is a request to firebase
self.db.collection(K.FStore.collectionName!).document((item?.idCard)!).delete() { err in
if err != nil {
print("err")
} else {
// here removal from the array, which is directly related to CollectionView
self.cards.remove(at: itemIndex)
}
}
}) {(finished) in
self.collectionView.reloadData()
}
//collection method
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// This is where the application crashes. That is, the method above works out completely, but I don’t understand how it works on ios 13, but not on ios 12 ..
return cards.count
}
对于任何想要将问题发送到“重复”或抛出带有“相同回复”字样的链接的人该资源的目的是帮助解决编程问题,碰巧我是Swift的新手,在我问自己之前,我真的看到并尝试解决了我的问题。
但是没有答案给出可以纠正该错误的结果。我请更高技能的人来帮助我,谢谢!
批处理更新在哪里(多个)?
您不需要performBatchUpdates
,该方法仅对多个同时更新有用。删除数据库中的卡,成功后,将卡从数据源阵列中删除,并删除集合视图中的动画项目。
我的建议假设itemIndex
派生的当前索引路径可用
item = self.cards[itemIndex]
self.db.collection(K.FStore.collectionName!).document((item?.idCard)!).delete() { err in
if let error = err {
print("An error occurred", error)
} else {
self.cards.remove(at: itemIndex)
self.collectionView.deleteItems(at: [indexPath])
}
}