Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No mainwindow.xib in Xcode 4 Confused how to have my TabBarController use a NavigationController

This was pretty easy in Xcode 3. But I'm totally lost in Xcode 4.* It looks like IB is not used at all. And all the TabBarController code is in code.

Question: How do I add a NavigationBarController to the default code that Xcode generates when using a TabBarController template?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];

UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];

self.tabBarController = [[UITabBarController alloc] init];

self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];

self.window.rootViewController = self.tabBarController;

[self.window makeKeyAndVisible];

return YES;

}
like image 710
Edward Potter Avatar asked Sep 13 '11 20:09

Edward Potter


1 Answers

As someone has mention you can add a xib file an configure the app to use it. Here is the code version in case you decide to go this route it's always best to know either way

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:    (NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    UIViewController *viewController1 = [[FirstViewController alloc] init];
    UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:viewController1];
    [viewController1 release]; viewController1 = nil;

    UIViewController *viewController2 = [[SecondViewController alloc] init];
    UINavigationController *navigationController2 = [[UINavigationController alloc] initWithRootViewController:viewController2];
    [viewController2 release]; viewController2 = nil;

    self.tabBarController = [[UITabBarController alloc] init];

    NSArray *viewController = [[NSArray alloc] initWithObjects:navigationController1, navigationController2, nil];
    [navigationController1 release]; navigationController1 = nil;
    [navigationController2 release]; navigationController2 = nil;

    self.tabBarController.viewControllers = viewControllers;
    [viewControllers release]; viewControllers = nil;

    self.window.rootViewController = self.tabBarController;

    [self.window makeKeyAndVisible];

    return YES;
}

This is written in the browser but it should work.

like image 184
Paul.s Avatar answered Oct 28 '22 19:10

Paul.s