Swift:Navigation between storyboards

From Hawk Wiki
Jump to: navigation, search

Navigate to Storyboard ID

var vc = storyboard.instantiateViewControllerWithIdentifier("loginViewController") as UIViewController
window?.rootViewController = vc

Navigate Segue by Identifier

First, drag a segue in storyboard and give it an identifier, then in the button action (or any action you like), do:

self.performSegueWithIdentifier("loginSegue", sender: self)

Get UIVewController from Navigation Controller

Sometimes, you want to access the UIViewController from a navigation controller

var vc = storyboard?.instantiateViewControllerWithIdentifier("navigationID") as UINavigationController
var v = vc.viewControllers[0] as ViewController // [0] represents the first level UIViewController under NavigationController