我已經下載了一組用戶照片從firebase和查看它作爲收集視圖(Instagram的樣子) 但即時通訊嘗試放大照片點擊另一個視圖控制器使用賽格,但其不工作。 我的代碼有什麼想法:從收集視圖控制器迅速傳遞圖像到另一個視圖控制器
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從未設置始終爲零。 – user863238