views:

1572

answers:

2

hi guys, i have found lots of info about this topic but have yet to crack how it is actually done.

I want to add a UITabBar in an iPhone app into an application already with a UIWindow / UINavigation Controller as the default Window.

i.e. add a tab bar to a typical NavControl app with, RootViewController.xib, MainWindow.xib, AddView.xib, DetailView.xib, EditView.xib etc... Which one do I edit?

If someone could point me to a visual example it would be appreciated. Screencast will surely get bonus points, this question is asked so much on the web, and I can't find a simple answer. See: http://stackoverflow.com/questions/482270/how-to-add-a-tabbar-to-navigationcontroller-based-iphone-app

Regards, @norskben

Samples

eg. the appdelegate is like this:

@interface SQLAppDelegate : NSObject {

UIWindow *window;
UINavigationController *navigationController;

}

@property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet UINavigationController *navigationController;

+2  A: 

I'm unclear on whether you want to add the tab bar "inside" one of the navigation controller views, or whether you want to take a navigation controller view and make it just one of the tabs in a tab bar controller with multiple tabs.

I think people would find a tab bar inside of a navigation controller subview to be a little odd so I'm going to guess you mean that you want to put a navigation controller inside a subview of a tab bar controller like I have in the image below:

alt text

"Logging View Controller" is loaded from a NIB file which contains a view and some other stuff.

If you want something like a tabbed view inside one of the subviews of a navigation controller, I would used a segmented control to switch views around inside that particular subview or something.

If you're trying to do what I did in the window above, just drag a new Tab Bar Controller into your main nib file, then drag the existing Navigation Controller onto the tab bar controller icon. That will make the nav controller one of the tabs inside the tab controller.

Nimrod
+2  A: 

OK, I stayed up for most of the night and worked it out. I based this from the inspiration above, and the Apple Recipes Sample SDK Code.

That Screenshot you posted was key. Heres Generally what I did:

*Started my Project, got it working as I wanted with UITableViews *Create TabBar in IB *Copied the exact same layout for the Application in Interface Builder, Connections etc. *Copied Code across relevant to the displays

(Connections Screenshot) http://img511.imageshack.us/img511/6267/screenshot20100105at121.png

Key Code:

AppDelegate.h:

@interface AppDelegate : NSObject <UIApplicationDelegate> {

    UIWindow *window;
    UINavigationController *navigationController;

UITabBarController *tabBarController; RootViewController *rootController;

}

@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController; @property (nonatomic, retain) IBOutlet RootViewController *rootController;

AppDelegate.m:

- (void)applicationDidFinishLaunching:(UIApplication *)application {

 [window addSubview:tabBarController.view];
 [window makeKeyAndVisible];
}

This is only samples of the key stuff I changed. Nothing outside AppDelegate was touched, except in interface builder. I kept on getting a white empty window loading up everytime until I changed

[window addSubview:[navigationController view]]; to

[window addSubview:tabBarController.view];

This one is key.

Hope this helps someone else too, I'm glad to sort it out

Regards, @norskben

norskben
Just wanted to thank you for this post and the follow up to it. Very helpful!
cdnicoll