Launching a login view before the tab bar controller is displayed

我们两清 提交于 2019-12-20 15:23:11

问题


I have an ios5 app developed using storyboards that currently displays a tab bar controller view on initial launch. I would like to display a login screen before the tab bar controller is displayed. The user would enter his username & password, the system would then authenticate the user and then if successful, display the tab bar controller.

I have tried the following 3 options with no luck.. any ideas ?

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    // Option 1
    UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
    PointsViewController *firstVC = [[tabBarController viewControllers] objectAtIndex:0];
    UIViewController *loginViewController = [[LoginViewController alloc] init];
    [firstVC.navigationController pushViewController:loginViewController animated:YES];

    // Option 2
    UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
    UIViewController *loginViewController = [[LoginViewController alloc] init];
    [tabBarController presentViewController:loginViewController animated:NO completion:nil];  

    // Option 3
    UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
    UIViewController *loginViewController = [[LoginViewController alloc] init];
    [tabBarController presentModalViewController:loginViewController animated:NO];

    return YES;
}

回答1:


Finally figured this one out.. here is what you need to do:

  1. Add a standalone login view to the storyboard.

  2. Select the login view and in the attributes inspector, check the 'Is Initial View Controller'. This will switch the initial view being launched from the tab controller to the login view, thereby solving the whole issue of displaying the login screen first.

  3. Add a button to the login view and create a segue to load the tab controller on push of the button. (Or you can create a segue from the login view to the tab controller view and programmatically invoke the segue as necessary).

  4. Select the login view and choose option Editor > Embed In > Navigation Controller

  5. In the attributes inspector for the Navigation controller, uncheck the 'Shows Navigation Bar' option (this is a cosmetic change; I am assuming you don't need a navigation bar showing on the login screen !!)

That's it :)




回答2:


Take a look at the following links

stackoverflow.com/questions/16351348/…

link2

link 3




回答3:


You can use a modal view. You can check if the user is logged in. If not then you can use a modal view to get the login information. You can create a UIViewController in the storyboard and then use the instantiateViewControllerWithIdentifier: method to create the login screen from the storyboard. Then simply show it modally.




回答4:


I met this problem just now and I have perfectly solved this by adding the following code, which you also didn't use.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    ...
    [self.window makeKeyAndVisible];
}


来源:https://stackoverflow.com/questions/9028534/launching-a-login-view-before-the-tab-bar-controller-is-displayed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!