Andy
Andy

Reputation: 770

Creating a Tab Bar with Storyboards for each Tab

I have created a tab bar Controller in my main.storyboard and have subclassed it.

I have created storyboards for each tab to organize my work like so:

@interface SATabBarController ()

@end

@implementation SATabBarController

- (void)viewDidLoad {
    [super viewDidLoad];

    NSMutableArray *viewControllersArray = [[NSMutableArray alloc]initWithCapacity:5];
    [viewControllersArray addObject:[[UIStoryboard storyboardWithName:@"Tab1" bundle:nil] instantiateInitialViewController]];
    [viewControllersArray addObject:[[UIStoryboard storyboardWithName:@"Tab2" bundle:nil] instantiateInitialViewController]];
    [viewControllersArray addObject:[[UIStoryboard storyboardWithName:@"Tab3" bundle:nil] instantiateInitialViewController]];
    [viewControllersArray addObject:[[UIStoryboard storyboardWithName:@"Tab4" bundle:nil] instantiateInitialViewController]];
    [viewControllersArray addObject:[[UIStoryboard storyboardWithName:@"Tab5" bundle:nil] instantiateInitialViewController]];

    [self setViewControllers:viewControllersArray];

}


@end

Now my question is. Is this okay to do? Are there any problems I might encounter with this method?

My storyboard was getting big and needed to find a way to separate.

Upvotes: 2

Views: 61

Answers (2)

Nikita Leonov
Nikita Leonov

Reputation: 5694

We did this on one of the projects and it is reasonable thing to do when your app is growing big. Storyboards are slow when growing big and this is why previously we used hacks to split them into multiple parts and now in iOS 9 we officially can do it without hacks. However this need to split storyboard is their issue. Main value of storyboards is to visually represent navigation complexity in a way that you can overview the whole thing while when splitting it into parts you can not do this. So technically it is right, conceptually it is wrong. Good luck :)

Upvotes: 0

Joshua Lee Tucker
Joshua Lee Tucker

Reputation: 160

There are two disadvantages to this approach that I can see immediately:

  1. View reuse - this approach makes it more difficult to reuse common view controllers across different tabs and will likely result in you implementing multiple copies of the same view.
  2. Bundle size - these presence of multiple storyboards will likely increase your bundle size unnecessarily.

Hope this helps,

Josh.

Upvotes: 1

Related Questions