开发者

how do i add a navigationViewController to a UIViewController?

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 = [[[UINa开发者_开发技巧vigationController 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...


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];


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜