programmatically load viewController class

76 views Asked by At

I want to load show (segue to) specific ViewController class when a user click a button.

I need to do it only in code without dragging and creating segues in the story board.

Say i have root viewController:

class ViewController: UIViewController {

func startPlayer(sender: AnyObject) {

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

The second viewController:

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

   }}

I am writing sort of framework and need it to happen automatically and can't make the user drag and create segue from story board

1

There are 1 answers

2
Dharmesh Kheni On BEST ANSWER

You can initiate nextview programetically this way:

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