我正在尝试将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()
}
答案 0 :(得分:2)
编写此代码
if let image = UIImage(named: mainpictures) {
self.mainImage.image = image
}
而不是
self.mainImage.text = mainpictures