【发布时间】:2019-10-24 06:28:06
【问题描述】:
我需要实现一些具有超过 15 个按钮作为过滤选项卡的文件管理器, 我添加了水平 CollectionView、自定义 Cell、两个数组。 单选效果很好, 但我需要全选并通过单击按钮取消全选 知道如何实现吗?
Selecting all the items in UICollectionView iOS, even the cells that are not visible
这个不行
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
}
【问题讨论】:
-
除了
all selected&all deselected还有其他状态吗?
标签: ios swift uicollectionview uicollectionviewcell jquery-ui-selectable