View Full Version : Override first view shown in tab bar app?

Feb 3, 2012, 09:59 AM
I've got a tabbar application using storyboards, that automatically shows the viewcontroller (firstVC) in the first tab.

I'd like to have a login-view appear at the beginning of the app instead of the first tab, but not have it as a separate tab.

The obvious solution would be to push the login-view from the firstVC, but the firstVC is not always the first viewcontroller to respond in the app - sometimes (depending if a push notification is received) another viewcontroller is shown first.

The best way I guess would be to initiate the login-view from the appDelegate, which always responds first (of course). But no matter how I initiate it from here, the content of the selected tab (for instance firstVC) is always shown instead.


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController; // Have to get the tabBarController, since appDel is not represented in storyboard
FirstViewController *firstVC = [[tabBarController viewControllers] objectAtIndex:0]; // Have to get the firstVC since tabbarcontroller does not implement pushViewController
LoginViewController *loginVC = [firstVC.storyboard instantiateViewControllerWithIdentifier:@"Login"];
[firstVC.navigationController pushViewController:loginVC animated:YES];

I also tried addSubview in AppDelegate.m, but the same thing happened there - the login-view does not appear on top (if at all).

I also tried an alternative approach by creating a new MainViewController that should be the initial view controller in the storyboard, and have the tabbarcontroller be a subview of it. This did not work at all - I simply could not make a connection between the MainViewController and the tabbarcontroller when the first was set as initial view controller (the reverse works fine, of course, adding a new tab).

Any suggestions?

Feb 3, 2012, 10:23 AM
What about presenting a modal view?