为什么要准备segue不发送图像swift?

时间:2017-03-13 13:18:57

标签: ios swift swift3

我试图将图像发送到另一个视图控制器。

override func prepare(for segue: UIStoryboardSegue, sender: Any!) {

    if (segue.identifier == "cropSegue") {

        let crop : CropViewController =  segue.destination as! CropViewController
        crop.cropImage = image
        print("prepared")
    }
}

并在接收端

class CropViewController: UIViewController {
@IBOutlet weak var imageView: UIImageView!
var cropImage : UIImage!

override func viewDidLoad() {
    super.viewDidLoad()
    self.imageView.image = cropImage
    // Do any additional setup after loading the view.
}

我不确定出了什么问题,但是图像没有被显示,甚至认为正在调用segue的准备工作。关于为什么的任何想法?

1 个答案:

答案 0 :(得分:0)

试试这个

class CropViewController: UIViewController {
@IBOutlet weak var imageView: UIImageView!
var cropImage : UIImage?

override func viewDidLoad() {
    super.viewDidLoad()
    if let image = cropImage {
         self.imageView.image = image
    }        
}