以编程方式加载 viewController class

programmatically load viewController class

我想在用户单击按钮时加载显示(转至)特定 ViewController class。

我只需要在代码中完成,而无需在故事板中拖动和创建 segues。

假设我有 root viewController:

class ViewController: UIViewController {

func startPlayer(sender: AnyObject) {

    // B.startView()  // should segue to ViewController B
}

第二个viewController:

class B:ViewController
{
   class func startView()
   {
      // Load this viewController and show it on screen (force segue to it) 

   }}

我正在编写某种框架,需要它自动发生,不能让用户从故事板中拖动和创建 segue

您可以通过以下方式以编程方式启动 textview:

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