选中时访问 CollectionViewCells 数据

Accessing a CollectionViewCells data when selected

我有一个 UICollectionViewCell 我想在点击时访问谁的数据。数据将在另一个视图控制器中使用...例如,当我点击一个朋友时,下一个 viewcontroller 呈现的将是一个包含点击的朋友数据的页面。

这是我的didSelectItemAt IndexPath

override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

    let layout = UICollectionViewFlowLayout()
    let vc = JoinGroupChatController(collectionViewLayout: layout)
    vc.selectedIndex = indexPath

    let liveCell = LiveCell()
    vc.descriptionLabel = liveCell.descriptionLabel.text

    present(vc, animated: true, completion: nil)
}

本质上这就是我想要做的,但是我需要 indexPaths 特定描述标签而不是默认的 liveCell 标签文本。

我知道我需要在某个地方使用 indexPath,只是不确定在哪里/如何使用。 有什么建议吗?

替换

let liveCell = LiveCell()

let liveCell = collectionView.cellForItem(at: indexPath) as! LiveCell