views:

596

answers:

1

Hi guys,

I've got a sample application on http://github.com/niklassaers/Test-iPhone-TabBar-App that shows my problem: I have a regular view-based application, and at some point (in this case when I click a button) I want to load a tabbar controller and display it. I believe this is what I should be doing:

MyTabBarController *tabs = [[MyTabBarController alloc] initWithNibName:@"TabBar" bundle:nil];
[self.view addSubview:tabs.view];

Unfortunately, this brings up a bit of black in the bottom of my main view and nothing more. I believed it should bring up the tabbar, the tabs, and the selected view. What is the correct way of loading a TabBarController (or making a TabBar controller if that's what I've done wrong) in a view-based application?

Cheers

Nik

+1  A: 

You should use a UINavigationController, then just push the tabs controller onto the nav controller when you're ready to display it.

Ben Gottlieb
Can I use the nav controller without having the navbar?
niklassaers
Here's a tutorial that may help: http://www.cimgf.com/2009/06/25/uitabbarcontroller-with-uinavigationcontroller-using-interface-builder/
Ben Gottlieb
Sure, just use [UINavigationController setNavigationBarHidden:]
Ben Gottlieb
Ok, as per your recommendation I've updated http://github.com/niklassaers/Test-iPhone-TabBar-App so that it's now based on UINavigationController, but that makes my button also disappear. Moving the adding code into the viewDidLoad also had no effect. Did I misunderstand something?
niklassaers
I'm afraid you may be misusing the viewController class. In general, on iPhone, ViewControllers are used to control full (or nearly full, excluding top and bottom bars) views. Thus, if you want to bring in a new view controller, it will control almost everything on screen. You'll need to create and add a new button in the Tabbed controller.
Ben Gottlieb