dk87 dk87 - 2 years ago 79
Swift Question

Is it possible to reference other Storyboards within Storyboards?

I am working on an iOS app and I want to split it into a couple of Storyboards, the problem is that I can't seem to figure out a way to setup references between Storyboards as an entry point.

For example I want my

to look something like this:

--> Authentication Storyboard --> Tabbed Storyboard --> ...

I am new to iOS development and I would expect this to be simple, but can't seem to find a way to do it.

Answer Source

Yes you can use multiple Storyboards in a project BUT No, you cant reference them directly from inside another storyboard.

Referencing a Storyboard to use on launch

Your project target can use any of the storyboards contained within it. The reference for the storyboard entry point can be found in the target settings.

enter image description here

  1. Select the target
  2. Select the General Tab
  3. In the dropdown for main interface select which storyboard to use initially.

Referencing a Storyboard in code

So in this example I wish to push a viewcontroller onto a navigation Controller. The viewcontroller I want to reference may be in a different storyboard or the current one I'm using. The code doesn't care...

    if let storyboard = UIStoryboard(name: "A2ndStoryboard", bundle: nil) {
      if let vc = storyboard.instantiateViewControllerWithIdentifier("SomeViewController" as String) {

        navigationController?.pushViewController(vc, animated: true)

When you want to reference ViewControllers like this you need to ensure that they are identified in the Storyboard correctly:

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download