tags:

views:

135

answers:

2

how do i add a navigationViewController to a UIViewController?

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

    loginViewController *vc1=[[loginViewController alloc]initWithNibName:@"login" bundle:[NSBundle mainBundle]];

    rootViewController* vc2 = [[[rootViewController alloc] init] autorelease];

    UINavigationController* navController = [[[UINavigationController alloc]

                initWithRootViewController:vc2] autorelease];
    NSArray* controllers = [NSArray arrayWithObjects:vc1,navController, nil];
    //loginViewController.viewControllers = controllers;



    [window addSubview:[self.loginController view]];
    // Override point for customization after application launch
    [window makeKeyAndVisible];
}

i'm stuck with this.need some help...

A: 

if I understand right, you should use

[window addSubview:[self.navController view]];

then you can send push/pop messages to self.navigationController to manage content of navigationController's stack.

Morion
A: 

The simplest way to do this is to change your init when setting up the navController. Also, you'll want to keep the navController around, probably as a member variable of your app delegate:

//in your header file:
....class definition
    UINavigationController    *_navigationController;
....

//in your implementation file:
_navigationController = [[UINavigationController alloc] initWithRootViewController: rootViewController];
//optional: if you want to start off 'one level in' to your navigation stack:
[_navigationController pushViewController: vc1 animated: NO];
[window addSubview _navigationController.view];
Ben Gottlieb
Thanks Ben, your answer is complete!
Prakash