Override first view shown in tab bar app?

Discussion in 'iOS Programming' started by Danneman101, Feb 3, 2012.

  1. macrumors 6502

    Aug 14, 2008
    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?
  2. Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State

Share This Page