我遇到了很大的麻烦,因为当我在我的单元格中选择一个单元格collectionView
并更改我的数组数据时,我收到了以下错误消息:
'无效更新:第0节中的项目数无效。更新后现有节中包含的项目数(2)必须等于更新前该节中包含的项目数(2),加上或减去从该部分插入或删除的项目数(1 插入,0 删除)加上或减去移入或移出该部分的项目数(0 移入,0 移出)。
它发生在 iOS 13 之前。在 iOS 13 和更高版本中运行良好。有我的代码:
import UIKit
import ReactiveKit
import Bond
//Its in my viewModel
var arrayOfObjects = MutableObservableArray<MyObject>([])
actionCollectionViewDidSelect.observeNext { [weak self] indexPath in
guard indexPath.row != 0 else { return }
guard let object = self?.arrayOfPhotoObjects[indexPath.row] else { return }
photoObject.isSelected = !photoObject.isSelected
if let value = self?.arrayOfObjects.value { self?.arrayOfPhotoObjects.value = value } // Gives error because there but I can't find solution.
}.dispose(in: disposeBag)
//Its in my ViewController
collectionView.reactive.selectedItemIndexPath.observe(with: viewModel.actionCollectionViewDidSelect).dispose(in: disposeBag)
viewModel.arrayOfObjects.bind(to: collectionView) { object, indexPath, collectionView in
let objectForIndex = arrayObjects[indexPath.row]
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "photoBoxCollectionViewCell", for: indexPath) as! MYCEll
cell.data = objectForIndex
return cell
}
}