获取自定义单元格的标识符

时间:2017-09-10 08:13:11

标签: ios swift swift3 uicollectionview

我有2个自定义单元格,即singleCell和doubleCell。我想知道当didSelectItemAt方法被激活时选择了哪一个。

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

感谢。

1 个答案:

答案 0 :(得分:1)

您可以通过查看cellForItem功能中的didSelectItemAt来执行此操作:

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