swift在两个视图控制器之间导航

时间:2015-08-05 09:35:09

标签: swift navigation uistoryboard

@IBAction func goView1(sender: AnyObject) {
    let view1 = self.storyboard.instantiateViewControllerWithIdentifier("view1") as ViewController
}

给出错误:

Value of optional type 'UIStoryboard' not unwrapped; did you mean to use '!' or '?' ?
请帮助我

2 个答案:

答案 0 :(得分:0)

 let view1 = self.storyboard.instantiateViewControllerWithIdentifier("ViewControllerIentifier") as? ViewControllerName

这将解决您的问题

答案 1 :(得分:0)

这样您就可以实例化并呈现新的viewController

@IBAction func goView1(sender: AnyObject) {

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let vc = storyboard.instantiateViewControllerWithIdentifier("view1") as! UIViewController
    self.presentViewController(vc, animated: true, completion: nil)

}

有关详细信息,请查看THIS教程。