Using Multiple Storyboards in iOS

Swift Multiple Storyboard - How to access specific one

If you want to access other storyboards you need to give that name.

self.storyboard will always point to your default storyboard. Instead do this :

let VC = UIStoryboard(name: "VCStoryBoardName", bundle: nil).instantiateViewController(withIdentifier: "InstructionScreenController") as! VC

Multiple storyboards: how small should they be?

Using storyboards has it's benefits, and if you want to keep using storyboards there is no reason you should be worried about performance impact of having many storyboards even a storyboard for each ViewController named after the ViewController.

Keep in mind that big storyboards take ages to load in the Xcode preview because it renders the whole storyboard file; however, when loading a screen in the app, it would not be loading the whole file just parsing the correct view controller and render only that. Knowing that, you should not see any performance problems from a bigger storyboard in your app.

The general practice shows that it's not good for you as developer to use big storyboards due to merge conflicts, especially if multiple developers are working on the same storyboard file.

If your layout is simple enough it might be worth doing everything in code.

How do I effectively use multiple Storyboards for 100+ view controllers?

Break up your view controllers by functional areas, creating a dedicated storyboard for each (or even more than one). You can then link them together using storyboard references if, for instance, you are worried you might lose the big picture view.

You can even do this storyboard refactoring afterwards by using the handy Extract Storyboard Xcode menu option (i.e., select a VCs subset and then click menu Editor > Extract Storyboard).

Of course, assuming you really need that many view controllers to begin with ;-)

UITabBarController with multiple storyboards

If your target is iOS 9 and above, you should create storyboard references for the view controllers you want to include in another storyboard. Here's how it works:

  1. Create a second storyboard, move the desired view controller into it and give it a Storyboard ID under the Identity inspector.

Identity inspector


  1. Go to your first storyboard and search for Storyboard Reference in the Object library.

Object library - Storyboard Reference


  1. Drag it into your storyboard and create a "view controllers" relationship with the tab bar controller just like you would with a view controller.

tab bar controller with view controllers in the storyboard


  1. Under the Storyboard Reference's Attribute inspector, change your settings accordingly. For Referenced ID, use the view controller's ID on the second view controller.

the Storyboard Reference's Attribute inspector

Connecting Multiple Storyboards in Swift

When your app needs to move to a new controller that's in a different storyboard, you have to instantiate the new storyboard, then instantiate the initial view controller there.

let sb = UIStoryboard(name: "SomeStoryboardName", bundle: nil)
let vc2 = sb.instantiateInitialViewController() as UIViewController // or whatever the class is of that initial vc


Related Topics



Leave a reply



Submit