2

我需要访问特定单元格并在 didSelectAt indexPath 上动态更改其内容

func collectionView(_ collectionView: UICollectionView, 
    didSelectItemAt indexPath: IndexPath) {
        if collectionView == self.trendHeaderView{
            print(indexPath.row)
            // Needs to access cell and change the 
            // content of cell i.e label text inside cell ??
    }
}
4

2 回答 2

1

您不能直接在 didSelectItemAt 中更改单元格的内容。如您所见,在 UICollectionView 中,单元格通过调用 dequeReusableCell 被重用。

所以我认为,为此制作模型很好。并更改 didSelectItemAt 中的模型内容。并请调用 reloadData 重绘collectionview。

于 2017-09-26T13:53:09.440 回答
0

我需要访问特定的单元格

不,你没有。你不应该直接干预单元格的内容。您需要访问集合视图的数据源正在使用的数据(“模型”)。您可以轻松做到这一点,因为您拥有indexPath. 更改数据,然后重新加载集合视图,以便它获取更改并显示它们。

于 2017-09-26T05:34:35.563 回答