iosipaduitabbarcontrollerstoryboarduistoryboard

How to connect two different Tab bar icons to same view controller with storyboard?


I have a tab bar controller in an iPad app with 6 items. Two of the icons will when you tap at them lead to the same view controller. This view controller has a list of items it will show, it will change slightly depending on which of the tab bar icons you tapped.

How do i set this up with storyboards? Its possible to drag the relationship twice to the same view controller, but then it just shows two of the same icons on the tab bar. I want the two choices to have different icons and name.


Solution

  • Like you've found, you can design the view controller once in the storyboard but won't be able to associate it with the tab bar controller more than once.

    What you can do is assign an identifier for it in the identity inspector, and then at runtime you can use the method -[UIStoryboard instantiateViewControllerWithIdentifier:] to instantiate a second copy of the view controller. You can insert that second copy into the tab controller using -[UITabBarController setViewControllers:animated:]