开发者

Modal LoginView with iPhone

开发者 https://www.devze.com 2023-03-15 01:23 出处:网络
I have a viewcontroller containing a TabController. Before this loads, I want a user to login so I can check what they have access to. In my AppDelegate, bot the rootViewController (with the tabs) and

I have a viewcontroller containing a TabController. Before this loads, I want a user to login so I can check what they have access to. In my AppDelegate, bot the rootViewController (with the tabs) and the LoginViewController are declared, and they're also wired up in IB:

I have this in my AppDelegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//  [window addSubview:[rootController vie开发者_如何学运维w]];
        [window addSubview:[loginViewController view]];
    [self.window makeKeyAndVisible];

    return YES;
}

My plan was to dismiss the login form after authenticating and show the rootController, but the rootController displays straight away. I was going to do:

-(IBAction)DidClickLoginButton:(id)sender {
     NotesAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
    [delegate.window addSubview:[delegate.rootController view]];
    [self dismissModalViewControllerAnimated:YES];
}

Modal LoginView with iPhone

Is there an easier way to do this? I can't see why the LoginViewController isn't presented.

EDIT: Eventually got this working by adding it to the rootController in my AppDelegate's didFinishLaunchingWithOptions method

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//  [window addSubview:[rootController view]];
    [self.window makeKeyAndVisible];
    LoginViewController *loginViewController =[[LoginViewController alloc] initWithNibName:@"LoginView" bundle:nil];
    [self.rootController presentModalViewController:loginViewController animated:YES];
    return YES;
}


I think it's actually much easier to do things 100% programmatically rather than with Interface Builder. Either way, in application:didFinishLaunchingWithOptions:, you want to do something like this:

[rootViewController presentModalViewController:loginViewController animated:NO];

Then, after the user logs in, do:

[rootViewController dismissModalViewControllerAnimated:YES];


Yes it would. As you are adding the root controller view on the window, and this would make it appear above all (even above the login view) and then your login view gets dismissed behind the root view, which you cannot see.

EDIT: One of the approach would be to have login controller above root in the beginning itself (root view controller presenting login view) and then happily dismiss the login view.

0

精彩评论

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