0
  1. Normally, we link the image from storyboard to viewcontroller by IBOutlet by this code:

    @IBOutlet private weak var resultImage: UIImageView!
    

we can update the image by calling this: resultImage.image = UIImage(named: "image"). It works ok

  1. However, when i call this in the prepare for segue, it found nil:

    let destinationDetail = segue.destination as! RestaurantViewController       
    destinationDetail.restaurantImage.image = UIImage(named: "image")
    

restaurantImage is an Outlet in RestaurantViewController: @IBOutlet weak var restaurantImage: UIImageView!

I dont understand why it found nil, please help!

Harshal Valanda
  • 5,331
  • 26
  • 63
Earthgod
  • 662
  • 1
  • 6
  • 21

1 Answers1

0

Because view controlle haven't been set up yet. you can use IBOutlet after view is load. In viewDidLoad or viewDidAppear of your destination viewController you will do something like this:

override func viewDidLoad() {
    super.viewDidLoad()
    resultImage.image = newImage
}
yogesh wadhwa
  • 711
  • 8
  • 16