[英]PrepareForSegue Swift (changing UIImage and UILabel)
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
. 所以我正在为我的应用程序编写
prepareForSegue
,但是在设置用于更改目标ViewController
的UIImage
和UILabel
的代码时遇到了问题。
What would be the code to change the images and UILabel
when segue to the next ViewController
? 当选择到下一个
ViewController
时,更改图像和UILabel
的代码是什么?
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "toTest") {
let destViewController : data3ViewController = segue.destinationViewController as data3ViewController
}
}
I you have in your data3ViewController
an UILabel
and an UIImage
, let says named myLabel
and myImage
respectively , then you should do the following : 我在
data3ViewController
一个UILabel
和UIImage
,分别说名为myLabel
和myImage
,那么您应该执行以下操作:
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. 上面对
destViewController.view
的调用确保在设置@IBOutlet
的值之前对其进行初始化。
I hope this help you 希望对您有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.