开发者

Best approach to change controller

开发者 https://www.devze.com 2023-04-04 06:38 出处:网络
My AppDelegate decides which controller to load depending if user is logged or not (using OAuth). So I have this

My AppDelegate decides which controller to load depending if user is logged or not (using OAuth).

So I have this

....
if ([auth isValid] == NO){
    // open the authentication screen
    AuthenticationViewController *controller = [[AuthenticationViewController alloc]init];
    self.window.rootViewController = controller;
    [controller release];
}else{
    // open the default view controller
    self.window.rootViewController = self.viewController;
}

[self.window makeKeyAndVisible];
return YES;

When the user opens the application for the first time or after L开发者_运维技巧og out, he/she will be redirected to AuthenticationViewController.

If the user closes (killing the app) and opens it again, because the authentication procedure is done, he/she will see the default view controller(UITabBarController).

What is the best approach to change between these controllers in real time?


What I normally do in these situations is create a UINavigationController (setting it to have no navbar at the top) and another UIViewController (perhaps the one with a UITabbarController in it (which I set as the rootViewController for the UINavigationController). Then in viewDidLoad or viewWillAppear you do you login logic and depending on the result, push or pop the correct UIViewController with NO animation.

0

精彩评论

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

关注公众号