iOS Swift 4 Coding

How to navigate to a view in code with Swift 4?

9 views August 31, 2018 August 31, 2018 bicobro 0

This article explains how to navigate to a specific view on a storyboard using code. Perform the following steps:

Step 1 – Give the view, to navigate to, a Storyboard ID

  1. Select the storyboard using the Project Navigator
  2. Within the storyboard, select the view you want to navigate to
  3. Go to the Identity Inspector
  4. Fill the Storyboard ID property with a unique view id (in the example below: “MyViewControllerStoryboardId”)

Step 2 – Write navigation code

    private func navigateToMyViewController() {
        let myViewController = storyboard?.instantiateViewController(withIdentifier: "MyViewControllerStoryboardId") as UIViewController?
        navigationController?.show(myViewController!, sender: self)
    }

 

 

Was this helpful?