使用Swift查看控制器的Segoe UI图像

时间:2015-02-21 15:04:22

标签: xcode swift uiimage segue

我正在尝试将uiimage传递给我的secondViewController但是我的编码仍然遇到错误。我如何将uiimage转换为我的secondViewController?

viewController.swift

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

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

       let destViewController : SecondViewController = segue.destinationViewController as SecondViewController

        destViewController.mainpictures = "background"
    }

SecondViewController

class SecondViewController: UIViewController {

    var mainpictures = String ()

    @IBOutlet var mainImage: UIImageView!

    override func viewDidLoad() {

        self.mainImage.text = mainpictures

        super.viewDidLoad()
    }

1 个答案:

答案 0 :(得分:2)

编写此代码

if let image = UIImage(named: mainpictures) {
     self.mainImage.image = image
}

而不是

self.mainImage.text = mainpictures