【发布时间】:2017-06-16 04:02:28
【问题描述】:
我已经从 firebase 下载了一组用户照片并将其作为收藏视图查看(类似 instagram) 但我试图放大使用 segue 在另一个视图控制器中单击的照片,但它不起作用。 关于我的代码的任何想法:
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
}
}
集合视图单元格是:
class ProfileCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var imageCollection: UIImageView!
}
最后是目标viewController:
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
}
}
【问题讨论】:
-
*它不是完整的代码,但我分享了最重要的几行
-
如果没有看到所有代码,很难知道如何回答这个问题,在摘录中提供的变量 photoThumbnail 从未设置并且始终为零。
标签: ios swift uicollectionview segue