Swift:Navigation between storyboards

From Hawk Wiki
Revision as of 04:08, 23 March 2015 by Hall (Talk | contribs) (Created page with "===Navigate to Storyboard ID=== <pre class="brush:swift"> var vc = storyboard.instantiateViewControllerWithIdentifier("loginViewController") as UIViewController window?.rootVi...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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