2017-09-10 60 views
0

我有2個自定義單元格singleCell和doubleCell。我想知道在didSelectItemAt方法觸發時選擇哪一個。獲取自定義單元格的標識符

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

謝謝。

回答

1

您可以通過在你的didSelectItemAt功能檢查cellForItem做到這一點:

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

感謝您的回覆。這是工作。 – Brkr

+0

@Brkr,太棒了!樂意效勞。 –

相關問題