如何使用swift以编程方式转换到不同故事板中的不同视图控制器?

时间:2015-12-19 16:40:35

标签: ios swift uiviewcontroller

let customerStoryboard =   UIStoryboard(name: "Customer", bundle: nil) //First(Current) storyboard 
let agentStoryboard =   UIStoryboard(name: "Agent", bundle: nil)  //Second storyboard

var otherVC = UIViewController!   // ViewController reference

otherVC = agentStoryboard.instantiateViewControllerWithIdentifier("AgentProfile") 

最后一个语句没有执行或显示结果,除此之外还需要做什么?

3 个答案:

答案 0 :(得分:1)

您只实例化视图控制器。要呈现它,您应该使用presentViewController方法

someVC.presentViewController(otherVC, animated: true, completion: nil)

答案 1 :(得分:1)

使用此代码显示第二个视图控制器。

let otherVC : AnyObject! = self.agentStoryboard.instantiateViewControllerWithIdentifier("AgentProfile")
self.showViewController(otherVC as UIViewController, sender: otherVC)

答案 2 :(得分:0)

let secondViewController = self.storyboard.instantiateViewControllerWithIdentifier("SecondViewController") as SecondViewController

self.navigationController.pushViewController(secondViewController, animated: true)