【问题标题】:Getting identifier of custom cells获取自定义单元格的标识符
【发布时间】:2017-09-10 08:13:11
【问题描述】:

我有 2 个自定义单元格,分别是 singleCell 和 doubleCell。我想知道在触发 didSelectItemAt 方法时选择了哪一个。

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    if singleSelected {
        print("SINGLE CELL SELECTED)
    } else {
        print("DOUBLE CELL SELECTED)
    }
}

谢谢。

【问题讨论】:

    标签: ios swift swift3 uicollectionview


    【解决方案1】:

    您可以通过在 didSelectItemAt 函数中检查 cellForItem 来做到这一点:

    if let singleCell = collectionView.cellForItem(at: indexPath) as? SingleCell {
        // singleCell selected
    } else {
        // doubleCell selected
    }
    

    【讨论】:

    • @Brkr,太好了!很高兴为您提供帮助。
    猜你喜欢
    • 2012-12-27
    • 1970-01-01
    • 2013-09-08
    • 1970-01-01
    • 2017-01-04
    • 1970-01-01
    • 2019-02-19
    • 1970-01-01
    相关资源
    最近更新 更多