Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Danneman101

macrumors 6502
Original poster
Aug 14, 2008
361
1
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.

AppDelegate.m
Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{  
    // DOES NOT SHOW LOGINVC ON TOP 
    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?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.