Rapture In Venice, LLC

:: Mobile Apps for iPhone, iPad, AppleTV and Watch

A UITabBarController Without Binding Items to Views

I’ve run across this on a project where I wanted what amounts to a UITabBarController for my iPhone app, but I want to have ONE shared view for 4 of the 5 tabs. This is impossible with UITabBarController as far as I can tell.

However, there is hope. With a slightly different implementation, you can have the Tab Bar in your app without the lockdown on functionality.

First, remove the UITabBarController from your MainWindow.xib or wherever else you have it.

Second, add a UITabBar to the window. This is in the library under “Windows, Views & Bars”. Notice it’s just the component, not the full controller.

Third, customize your items, and add Tab Bar Items as needed.

Fourth, set the delegate of this object to whatever listener you want. I do this programmatically, but you can do it how you like. You just need a class that implements UITabBarDelegate, *not* UITabBarControllerDelegate.

Fifth, implement:

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
    // do something based on item
}

Sixth, add logic so that based on the item (you can compare by using IBOutlet to get a reference to all the items or look at the labels). In my case, I transformed by single view based on which item was selected.

And presto!

  • Print
  • Facebook
  • Twitter

John Blanco

John Blanco is a freelance iOS developer in Denver, CO. He's been developing mobile apps for 12 years, starting during the medieval days of Java ME, making him the ultimate hipster mobile engineer. Follow him on Twitter!

More Posts

Follow Me:
Twitter

,

Comments are currently closed.