@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 '?' ?
请帮助我
答案 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教程。