I am trying to delete a cell form UICollectionView but I am having an error for "Invalid Updates"
'Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (9) must be equal to the number of items contained in that section before the update (9), plus or minus the number of items inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).'
and I tried updating my DataModel before removing the items from the CollectionView, but it didn't work.
here is my Code:
func didChangeQunatityOfCartProductAt(index: IndexPath?, product: ItemsModel?) {
if let quantity = product?.quantity{
if let indexPath = index{
if quantity == 0{
self.products.remove(at: indexPath.row)
self.collectionView.deleteItems(at: [indexPath])
}
}
}
}
and here is my numberOfItemsInSection Function:
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return products.count
}
I keep getting the same results even though all I have found on the web is same solution.