PrepareForSegue Swift(改变UIImage和UILabel)

时间:2015-02-20 22:24:20

标签: xcode swift uiimage segue

因此,我正在为我的应用编写prepareForSegue,但在设置代码以更改目标UIImage的{​​{1}}和UILabel时遇到问题。< / p>

更改图片的代码是什么?{seg>到下一个ViewController时会UILabel

ViewController

1 个答案:

答案 0 :(得分:2)

我有data3ViewController UILabelUIImage, 分别为myLabelmyImage,您应该执行以下操作:

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")
   }
}

destViewController.view上方的调用可确保在设置值之前初始化@IBOutlet

我希望这可以帮到你