【问题标题】:Identify unique CollectionViewCells识别唯一的 CollectionViewCells
【发布时间】:2015-11-28 01:30:02
【问题描述】:

我希望每个 CollectionViewCell 显示图像并在被点击时隐藏标签。但是如果用户滚动图像突然显示在其他没有被触摸的进程中。如何识别某些细胞?

override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {

    println("user tapped on door number \(indexPath.row)")

    let cell = collectionView.cellForItemAtIndexPath(indexPath) as! MyCollectionViewCell

    if (cell.myLabel.text == "1") {
        one = true

            if (cell.myLabel.hidden) {
                cell.myLabel.hidden = false
                cell.MyImageView.image = nil

            }
            else {
                cell.myLabel.hidden = true
                cell.MyImageView.image = UIImage(named:"1")!
            }
    }

【问题讨论】:

    标签: ios swift uicollectionviewcell collectionview


    【解决方案1】:

    这是因为单元格被重复使用,所以不是更改每个单元格,而是在被点击的单元格的索引处更改数据源。

    【讨论】:

    • 你能举个例子吗?
    猜你喜欢
    • 2019-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-18
    • 1970-01-01
    • 2012-12-11
    • 1970-01-01
    • 2014-09-11
    相关资源
    最近更新 更多