ios - UICollectionViewCell 未选中

标签 ios swift uicollectionviewcell

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

所以我想当我单击选定的单元格时我想取消选择同一单元格

我使用这个代码

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 单元格上的 Taps 事件,并且当用户点击已选定的单元格时,取消选择它。

关于ios - UICollectionViewCell 未选中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36447056/

相关文章:

ios - 如何在 swift 中使用 header 完成 api 调用

ios - 更新Xcode到7.0后出现错误

swift - CollectionViewCell 在 iphone 5 屏幕外

swift - 用户第一次在collectionview Swift 5中添加图像单元时显示选择的图像而不是默认图像

ios - Container ViewController with 3 children must have a common parent view controller 错误

swift - 在 UIPickerView 中创建 3 列,也使用 append 功能

ios - tableView中抛出错误时该怎么办(_ :numberOfRowsInSection:)?

ios - 无法使用 AutoLayout 设置 UICollectionViewCell 的宽度

iphone - 现在运行事件指示器

ios - 是否可以在 Swift 上使用 iOS 自动更正库?