Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UICollectionViewCell未选中_Ios_Swift_Uicollectionviewcell - Fatal编程技术网

Ios UICollectionViewCell未选中

Ios UICollectionViewCell未选中,ios,swift,uicollectionviewcell,Ios,Swift,Uicollectionviewcell,当我选择单元格时,选中,当我选择另一个单元格时,选中并取消选中上一个单元格,确定 所以当我点击选中的单元格时,我想取消选中相同的单元格 我使用这个代码 override var selected: Bool { get { return super.selected } set { if newValue { super.selected = true

当我选择单元格时,选中,当我选择另一个单元格时,选中并取消选中上一个单元格,确定

所以当我点击选中的单元格时,我想取消选中相同的单元格

我使用这个代码

override var selected: Bool {
       get {
            return super.selected
        }
        set {
            if newValue {
                super.selected = true
                self.shadowView.backgroundColor = UIColor(hexString: "EEEEEE")
            } else if newValue == false {
                super.selected = false
                self.shadowView.backgroundColor = UIColor.whiteColor()
            }
        }
    }


}

我认为这个小部件的行为就像一个单选按钮,一旦选择了一个,就不能用标准行为取消选择同一组的所有按钮

因此,您必须在
UICollectionViewCell
单元格上侦听点击事件,当用户点击已选择的单元格时,取消选择它