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;
}
Take a look at the following links
stackoverflow.com/questions/16351348/…
link2
link 3
Finally figured this one out.. here is what you need to do:
Add a standalone login view to the storyboard.
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.
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).
Select the login view and choose option Editor > Embed In > Navigation Controller
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 :)
I met this problem just now and I have perfectly solved this by adding the following code, which you also didn't use.
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.