UITabBarController with multiple storyboards
Asked Answered
J

1

16

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?

Jahvist answered 23/8, 2017 at 12:54 Comment(2)
Why do you want to divide tabbar controller? Why not its upcoming views?Hebdomadary
My question is "How to divide Tab Bar Controller & the associated tab's view controllers into multiple storyboards?", I am not saying divide Tab Bar Controller only. So, only divide upcoming views is also a good suggestion to me.Jahvist
T
31

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

Tainataint answered 23/8, 2017 at 13:1 Comment(4)
@Jahvist This is the only solution if you don't want to use any code for setup. You have to keep in mind though that storyboard references require iOS >= 9.Illegalize
@AndréSlotta Thanks, I included this in my answer.Plumper
My target is set to 9.0. How are you getting around this error: "Illegal Configuration: Storyboard References cannot be the destinations of relationship segues prior to iOS 9.0"Pinsky
the destination VC added but it's not showing tabbar icon. can you help with that?Danette

© 2022 - 2024 — McMap. All rights reserved.