Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 583
Leem.fin Avatar asked Aug 23 '17 12:08

Leem.fin


People also ask

Can we use multiple storyboards in one application?

A storyboard is meant to explain a story, not a saga. An app's storyboard can be easily divided into multiple storyboards, with each one representing an individual story.

How do I add views to my storyboard?

In storyboards, you add views by dragging them onto the view controller scene. For example, the following figure shows a view controller with an image view and button on an iPhone.


1 Answers

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

like image 189
Tamás Sengel Avatar answered Oct 08 '22 10:10

Tamás Sengel