Difference between revisions of "Swift:Navigation between storyboards"

From Hawk Wiki
Jump to: navigation, search
(Created page with "===Navigate to Storyboard ID=== <pre class="brush:swift"> var vc = storyboard.instantiateViewControllerWithIdentifier("loginViewController") as UIViewController window?.rootVi...")
 
(No difference)

Latest revision as of 04:08, 23 March 2015

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