swift - 我们如何在集合视图中重新加载标题视图
问题描述
我一直在寻找一种方法来重新加载我的集合视图标题。所以我有一个集合视图标题和一个只包含图像的 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
}
因此,当我选择一个单元格时,视图变为红色,当我取消选择它时,视图变为黑色。此处的此视频显示了无需重新加载 collectionView 的行为。现在这里是我想重新加载标题视图。
如果我确实使用了 collectionView.reloadData(),这就是结果。我如何能够重新加载标题或 collectionView,其中标题视图显示选定的单元格图像并变为红色。
解决方案
You can try like global instance for that. Like
class YourClass: UIViewController {
/// Profile imageView
var profileImageview = UIImageView()
}
In CollectionView cellforItem assign a imageview. Like
let imageCell = collectionView.cellForItem(at: indexPath) as! CollectionCell
profileImageview = imageCell.imageView
Then when every you selecting collectionViewCell
You can call a function to change a image of imageView. Like
func updateImage() {
profileImageview.image = UIImage()
}
推荐阅读
- python - 从 Django 中的表中获取最高值
- sql - 在 HANA 中创建临时表并使用 WITH 子句放置数据
- python - 关于 for 循环的“运行时间”的问题
- php - Divi 主题生成器,向 Wordpress 模板页面添加页眉和页脚
- python-3.x - 使用 Rply 获取字符串输出会抛出 ParserGeneratorError: Expecting :
- html - 在AngularJs中重置过滤器
- php - Latte (Nette) PHP 框架 - 全局禁用转义(自动添加“noescape”)
- java - JavaFX Canvas-绘图
- reactjs - Reactjs - 从 api 响应中过滤数据
- python - Tensorflow 文本生成未返回有效索引