Language: Swift 3
OS: iOS 9+
Before iOS 9 came out, to hop from one storyboard to another, you would have to write a few lines of code similar to this:
The code from goToStoryboardOldSchoolWay.swift:
- Get a reference to the storyboard you want to go to. In this case, named AccountCreation.
- Instantiate the initial view controller named CreateAccountViewController.
- Present the view controller.
Once iOS 9 was delivered, there was this cool UI view element that can be added to transition from one storyboard to another called Storyboard Reference. As you can see in the text, it is a placeholder for a view controller that is located in another storyboard:
Assuming you have your initial storyboard, you’ve created another storyboard that has a view controller set as the initial view controller, and you want to get to it; follow these next couple of steps to reference it to your next storyboard as I did for the current project:
- Drag a Storyboard Reference onto the storyboard editor
- Select the Storyboard Reference, open the Attributes Inspector, and enter/select the name of the the next storyboard
- Create a segue to the Storyboard Reference so the program knows what action will invoke the segue. For instance, when you press the ‘Create an Account’ button, it should segue to the AccountCreation.storyboard
You should see something like this in the end:
That’s pretty much it. Now test it to see if you can use the Storyboard Reference to hop from one storyboard to another. Also, a friend of mine asked about backwards compatibility. At the time of this writing, only about 3% of users are using something below version 9.0; so I wouldn’t be too worried.
Happy coding!