I need realize some filer with over 15 buttons as filter tabs, I added horizontal CollectionView, custom Cell, two array’s. Single selection works well, but I need select all and deselect all by button click any idea how to realize it?
Selecting all the items in UICollectionView iOS, even the cells that are not visible
this one doesn't work
var arraySelectedFilterIndex = [IndexPath]()
var arraySelectedFilterData = [String]()
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.filterTitles.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "FilterCell", for: indexPath) as! FilterCell
cell.titleL.text = String(filterTitles[indexPath.row])
cell.pointIMG.image = UIImage(named: filterTitles[indexPath.row] + "40")
if arraySelectedFilterIndex.contains(indexPath) { // You need to check wether selected index array contain current index if yes then change the color
cell.isSelected = true
}
else {
cell.isSelected = false
}
cell.layoutSubviews()
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("You selected cell #\(indexPath.item)!")
Haptico.shared().generate(.light)
let strData = filterTitles[indexPath.item]
if arraySelectedFilterIndex.contains(indexPath) {
arraySelectedFilterIndex = arraySelectedFilterIndex.filter { $0 != indexPath}
arraySelectedFilterData = arraySelectedFilterData.filter { $0 != strData}
}
else {
arraySelectedFilterIndex.append(indexPath)
arraySelectedFilterData.append(strData)
}
collectionView.reloadData()
print(arraySelectedFilterData)
}
@IBAction func selectAllA(_ sender: Any) {.
//here need add code with All Select and Deselect functions
}