gpt4 book ai didi

ios - 将图像从 Collection View Controller 快速传递到另一个 View Controller

转载 作者:行者123 更新时间:2023-11-28 10:54:10 25 4
gpt4 key购买 nike

我已经从 firebase 下载了一组用户照片并将其视为收藏 View (类似 Instagram)但我试图使用 segue 放大在另一个 View Controller 中单击的照片,但它不起作用。关于我的代码的任何想法:

class ProfileViewController: UIViewController{
var photoThumbnail: UIImage!
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "collection_cell", for: indexPath) as! ProfileCollectionViewCell
cell.imageCollection.downloadImage2(from: currPosts[indexPath.row].photoUrl)
cell.imageCollection.image = photoThumbnail
return cell
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
performSegue(withIdentifier: "photoViewSegue", sender: nil)
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
var destViewController : EnlargePhotoViewController = segue.destination as! EnlargePhotoViewController
destViewController.labelText = "test" //**** this works
destViewController.myImage = photoThumbnail //**** this doesnt work
}

}

Collection View 单元格是:

class ProfileCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var imageCollection: UIImageView!

}

最后是目标 View Controller :

class EnlargePhotoViewController: UIViewController {

@IBOutlet weak var myLabel: UILabel!
@IBOutlet weak var enlargedPhoto: UIImageView!

var labelText = String()
var myImage: UIImage!

override func viewDidLoad() {
super.viewDidLoad()

myLabel.text = labelText
enlargedPhoto.image = myImage
}
}

最佳答案

尝试改成这段代码:

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath) as! ProfileCollectionViewCell

photoThumbnail = cell.imageCollection.image
performSegue(withIdentifier: "photoViewSegue", sender: nil)
}

关于ios - 将图像从 Collection View Controller 快速传递到另一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44580603/

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