在更改视觉状态时取消选择collectionView中的所有单元格

时间:2017-04-02 18:05:47

标签: ios arrays swift uicollectionview

我有一段代码应该取消选择集合视图中的所有单元格(myHobbiesCV),同时根据cellForItemAt更新它们的视觉状态(只是一个alpha变化!没什么了不起的。)

将所有选定的单元格添加到名为myHobbiesArraySelected的字符串数组中。当按下按钮[取消选择所有爱好]时,它应该擦除myHobbieArraySelected数组,并将所有单元格更改为未选择的可视状态。

@IBAction func deselectAllPressed(_ sender: UIButton) {
    let allSelected = myHobbiesCV.indexPathsForSelectedItems
    for deselect in allSelected! {
        print("deselected all")
        myHobbiesCV.deselectItem(at: deselect, animated: true)
        // This is essentially doing nothing :(
    }
    myHobbiesArraySelected.removeAll()
    print(myHobbiesArraySelected)
}

它使用removeAll清除数组,但是单元格的视觉状态根本没有变化。

如何将单元格视觉状态更改为未选中,同时擦除数组?

1 个答案:

答案 0 :(得分:2)

如何枚举所有可见细胞并改变它们的外观  (如果你想取消选择它们?)

for cell in collectionView.visibleCells {
    // Change alpha
}
相关问题