Leem.fin
Leem.fin

Reputation: 42602

UITabBarController with multiple storyboards

I am developing an iOS app with Xcode 8 and Swift 3.

I have a Tab Bar Controller with one tab view embedded into a Navigation Controller, as you see below:

tab bar controller with one tab view

As the project continues, the storyboard is getting bigger. I really don't like it. So, I would like to divide it into multiple storyboards.

My question is:

How to divide a Tab Bar Controller & the associated tab's view controllers into multiple storyboards? What is the best practice to do it? And how to do it?

Upvotes: 16

Views: 5383

Answers (1)

glyvox
glyvox

Reputation: 58049

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

Upvotes: 31

Related Questions