开发者

How to set up Navigation Controller -> Root View in code (iPhone SDK)

I need the ability to bypass the default RootViewController you get when you pick a navigation controller project type in XCode. I need this because I want to go down a different path depending on whether the app has been configured (sign up/login screens if not). Could someone point me to an example where in the AppDelegate the NavigationController is hooked to another controller (in this case SignupController) via code?

Here is what I have, but it doesn't let me change the title. And in the MainWindow.xib, it's still tied into the default RootViewController.

(void)applicationDidFinishLaunching:(UIApplication *)application {    
    [[UIApplication sharedApplication] 
    // if no config, load up the SignupController

    SignupController* signupController = [[SignupController alloc] initWithNibName:@"SignupController" b开发者_开发技巧undle:nil];
    [window addSubview:[navigationController view]];
    [window makeKeyAndVisible];


You can do something like this:

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

    if( hasConfig ) {
        [window addSubview:[navigationController view]];
    } else {
        SignupController *signupController = [[SignupController alloc] initWithNibName:@"SignupController" bundle:nil];
        [window addSubview:signupController.view];
        [signupController release];
    }
    [window makeKeyAndVisible];

It becomes awkward to switch back to your navigation controller once sign in is complete. (Assuming you are showing a sign in screen.)

Why not use a modalviewcontroller?

In your RootViewController.m:

- (void)viewDidAppear {
   [super viewDidAppear];

    if( notLoggedIn ) {
        SignupController *signupController = [[SignupController alloc] initWithNibName:@"SignupController" bundle:nil];

        [self presentModalViewController: signupController animated:YES];
        [signupController release];
    }
}

SignupController.m

- (void)didSignInOk {
    //this will dismiss the sign in screen
    [self.parentViewController dismissModalViewController];
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜