Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone: Add a Tab Bar controller programmatically to a navigation controller

I'm developing an iPhone application and I started out with the navigation based template. But now i'd like to add a Tap Bar controller at the bottom and I would like to do this without using Interface Builder. Can anybody tell me how to do this? Thanks in advance!

like image 967
Chris Avatar asked Mar 16 '11 20:03

Chris


2 Answers

This is not supported by the framework.

A tab bar controller can only be created as follows:

  • Directly in your application’s main window.
  • As one of the two root views in a split view interface. (iPad only)
  • Present it modally to display some data that requires its own mode-based organization.
  • Display it from a popover. (iPad only)

In other words, a tab bar controller can't be pushed onto a navigation controller.

More info here:

http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/TabBarControllers/TabBarControllers.html#//apple_ref/doc/uid/TP40007457-CH102-SW1

like image 59
Philippe Leybaert Avatar answered Oct 12 '22 12:10

Philippe Leybaert


If you are asking how to start with a navigation controller and then allow the user to navigate to a view with a tabbar, I do exactly this in my iPad app. Go to the website listed in my profile if you are interested to see how my app uses the tab bar.

Although, I used Interface Builder to accomplish it. In Interface Builder, I created sort of a master view that contains the tabbar control at the bottom and a "content" UIView above it. As the user tabs through views, the "content" view is programmatically assigned the view that the user is interested in.

I suppose you could also accomplish it without IB. Just use code this:

UITabBar *aTabBar = [UITabBar alloc] init];
[[self yourView] addSubview:aTabBar];

Of course, you will want to create tab bar items and assign view controllers to each item. You may also have to tweak the tab bar control's layout params so that it sits at the bottom of the view.

like image 38
Gregorius T Avatar answered Oct 12 '22 11:10

Gregorius T