2

I have a tab-based application, and I want to reuse the same view layout for two of the tabs.

The views share the same UIViewController subclass, but it seems they can't share the same scene/layout in my storyboard. I can't put two tab items in one scene/view.

The way I have "solved" it is by simple adding another view, copy-paste the layout from the original view, and connect a segue for the new tab item. Then in the viewWillAppear method I make sure to display different contents depending on which tab is selected. But this is a hassle if I want to change something in layout of the original view.

Is there a more elegant way of achieving this using Storyboards, or do I have to resort to creating the views programmatically?

pojo
  • 5,892
  • 9
  • 35
  • 47

1 Answers1

0

You can create a single view based application. and add tab-bar controller on it with whichever tabs you want. Then just add tab-bar delegate methods where you can set the functionality for each tabs on same view.

This is delegate method where you can add your functionality for each tabs by setting tags for each tab.

-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
  if(item.tag ==0)
 {
 }
}
iMash
  • 1,178
  • 1
  • 12
  • 33
  • I already use the UITabBarItem.tag to decide which content the view should have. My question is if it's possible to layout the view in Storyboard, and connect both of the tabbed views to that view layout (scene), so that I don't have to copy-paste between two layouts in Storyboard. – pojo Mar 09 '12 at 09:24