views:

61

answers:

2

My app is a tab bar application, which one of the tabs is a TableViewController instead of a viewController which works fine (the table displays great) but where and how do I add UINavigationController to it? :-)

+2  A: 

You can do this 2 different ways... in IB or code. If I'm dealing with a TabBar I usually do it in IB. All you have to do there is is drag a NavigationController object where your tableview object currently sits... then just make your tableviewcontroller the first child of your new navigation object.

TabBarController
-(Tab Bar)
-NavigationController
--(Navigation Item)
--TableViewController

or

If you want to do it in code... I would just set it up within your app delegate (usually because a tab bar is at the highest point in your app... meaning it appears right away after loading):

// Create a tabbar controller and an array to contain the view controllers
tabBarController = [[UITabBarController alloc] init];
NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] initWithCapacity:numberOfTabs];

// setup the view controllers
UINavigationController *myNavigationController;
myNavigationController = [[UINavigationController alloc] initWithRootViewController:myTableViewController];

// add to tab bar controller
[localViewControllersArray addObject:myNavigationController];
tabBarController.viewControllers = localViewControllersArray;

// add the tab bar to the window
[window addSubview:tabBarController.view];

You should then release the objects you just created since they will be retained by the TabBarController and Navigation Controller. Hope this helps

Ryan Ferretti
Well that did make sense, and I now have something that looks like this - http://sht.tl/hfEE - But it doesnt work.. it works just like it did before, which is ok as there are no errors but there isnt a bar at the top still :(
tarnfeld
A: 

As Ryan noticed you can make it easily using IB. Here is how you can achieve this:

  1. Launch Xcode and create new Tab Bar Application project.
  2. Under resources group find MainWindow.xib and double click it to open in Interface Builder.
  3. Next, select Tab Bar Controller object and open Inspector window (Command + Shift + I).
  4. Notice "View Controllers" section in Inspector (Sample screenshot) then click on View Controller popup and change value from View Controller to Navigation Controller.

That's it! Now you can use your UITableViewController subclass inside this UINavigationController.

Roman Busyghin