Rapture In Venice, LLC

:: Freelance iOS Development & Team Augmentation

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 living in Lakewood, Colorado. He's been developing mobile apps for over 15 years, beginning in the medieval days of Java ME and Blackberry and all the way through iPhone and Android! He's led development on dozens of apps across a wide variety of domains such as retail, vision, orthotics, games, sports, and more!

More Posts - Website

Follow Me:
LinkedIn

,

Comments are currently closed.