Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launching a login view before the tab bar controller is displayed

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;
}
like image 643
abu.marcose Avatar asked Jan 27 '12 03:01

abu.marcose


2 Answers

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 :)

like image 106
abu.marcose Avatar answered Oct 21 '22 04:10

abu.marcose


Take a look at the following links

stackoverflow.com/questions/16351348/…

link2

link 3

like image 38
Suraj K Thomas Avatar answered Oct 21 '22 03:10

Suraj K Thomas