【发布时间】:2018-11-26 05:39:00
【问题描述】:
我一直在寻找一种方法来重新加载我的集合视图标题。所以我有一个集合视图标题和一个只包含图像的 CollectionViewCell。现在,当按下单元格时,我想在标题视图中显示图像而不调用 collectionView.reloadData()。这就是我的 didSelectItemAt 和 didDeselectItemAt 方法的样子。
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
selectedImage = images[indexPath.item]
let imageCell = collectionView.cellForItem(at: indexPath) as! CollectionCell
imageCell.photoBackgroundView.backgroundColor = .red
collectionView.reloadData()
}
override func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
let imageCell = collectionView.cellForItem(at: indexPath) as! ImagePickerCell
imageCell.photoBackgroundView.backgroundColor = .black
}
所以当我选择一个单元格时,视图变为红色,当我取消选择它时,视图变为黑色。这个video here,展示了不重新加载collectionView 的行为。现在这里是我想重新加载标题视图。
如果我确实使用了 collectionView.reloadData(),这是outcome. 我如何能够重新加载标题或标题视图显示所选单元格图像并变为红色的 collectionView。
【问题讨论】: