I have 5 array in all my cells in collection view.
How can I delete multiple selected cells from collection view?
var _selectedCells : NSMutableArray = []
Delete button
@IBAction func DeleteButton(_ sender: UIBarButtonItem) {
// How delete multiple selected cells from collection view
}
Add cell index
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if self.EditToolBar.isHidden == true {
self.performSegue(withIdentifier: "DetailVC", sender: indexPath.item)
} else {
print("EditMode")
_selectedCells.add(indexPath)
print("selectedCells - \(_selectedCells)")
}
}
Delete cell index
func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
if self.EditToolBar.isHidden == true {
} else {
print("EditMode")
_selectedCells.remove(indexPath)
print("unselectedCells - \(_selectedCells)")
}
}
Crash
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (5) must be equal to the number of items contained in that section before the update (5), plus or minus the number of items inserted or deleted from that section (0 inserted, 2 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).'
numberOfRowsInSectionmethod, return_selectedCells.countthen in eachdidDelectanddidDeselectmehtods, relod. TableView - Ali Moazenzadeh