gpt4 book ai didi

ios - 如何将UICollectionViewCell中的图像显示到另一个UIImageView? ( swift 3)

转载 作者:行者123 更新时间:2023-11-30 12:07:06 31 4
gpt4 key购买 nike

这是我的 View Controller 的样子:

Collection View Controller

UICollectionViewCell 有自己的自定义类,带有用于 ImageView 的 @IBOutlet。但是,每当我尝试在 CollectionViewController 上使用 didSelectItemAt 函数时, ImageView 导出都不会被识别。我想做的是,当用户从 Collection View 中按下图像时,它将显示在 bigImageView 上( Collection View 之外)。

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

let cell = collectionView.cellForItem(at: indexPath)

bigImageView.image = cell.smallImageView.image

}

错误提示:

"Value of type 'UICollectionViewCell?' has no member 'smallImageView' "

我错过了什么?请赐教。提前致谢!

最佳答案

您需要将单元格转换为正确的子类才能访问 smallImageView 属性:

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

guard let cell = collectionView.cellForItem(at: indexPath) as? YourSubclass else {
return
}

bigImageView.image = cell.smallImageView.image
}

关于ios - 如何将UICollectionViewCell中的图像显示到另一个UIImageView? ( swift 3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46551667/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com