Saturday, June 4, 2016

Navigation

Here are some ways to programmatically control navigation.
In order to find your view controllers by identifier you will have to first set the identifier (after selecting it on the storyboard):

With NavigationController

 
// Navigate to another view controller
let vc = storyboard?.instantiateViewControllerWithIdentifier("myViewController")
navigationController?.pushViewController(vc!, animated: true)

// Go to previous view controller
dismissViewControllerAnimated(true, completion: nil)

// Go to the starting view controller
navigationController?.popToRootViewControllerAnimated(true)
 

Without NavigationController

 
// Navigate to another view controller
let vc = storyboard?.instantiateViewControllerWithIdentifier("myViewController")
present(vc!, animated: true, completion: nil)

// Go to previous view controller
dismissViewControllerAnimated(true, completion: nil)
 

With Segue

 
// Navigate to another view controller
// You have to give your Segue an identifier to use this
performSegue(withIdentifier: "mySegue", sender: self)
 

(Swift 2.2)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

SwiftUI Search & Filter with Combine - Part 3 (iOS, Xcode 13, SwiftUI, 2...

In part 3 of the Searchable video series, I show you how to use Combine in #SwiftUI for the search and filter logic connected to the searcha...