Reputation: 529
So I'm writing the prepareForSegue
for my app but having issue setting up the code for changing the UIImage
and UILabel
for the destination ViewController
.
What would be the code to change the images and UILabel
when segue to the next ViewController
?
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "toTest") {
let destViewController : data3ViewController = segue.destinationViewController as data3ViewController
}
}
Upvotes: 1
Views: 738
Reputation: 23451
I you have in your data3ViewController
an UILabel
and an UIImage
, let says named
myLabel
and myImage
respectively , then you should do the following :
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "toTest") {
var destViewController : data3ViewController = segue.destinationViewController as data3ViewController
let _ = destViewController.view
destViewController.myLabel.text = "Something"
destViewController.myImage = UIImage(named: "photo")
}
}
The call above to destViewController.view
ensure that the @IBOutlet
's are initialized before set it values.
I hope this help you
Upvotes: 2