Search code examples
uiviewcontrolleruitabbarcontrolleruistoryboarduiapplicationdelegate

Need to load UIViewController from appdelegate and hide UITabBarController when loaded in Storyboard App


I have an app, in that app if its the first time the user has run the app I need to display a welcome screen and then present some 1st time only setup information for the app. I think the best place to put this is in the appdelegate (didFinishLaunchingWithOptions), maybe need correction if wrong. In the app delegate I call this method:

-(void) checkSetupOccured
{

    NSString *filePath = [self dataFilePath];
    if (![[NSFileManager defaultManager] fileExistsAtPath:filePath])
    {
        //File doesn't exist, first time ran or installed
        UITabBarController *MyTabViewController = (UITabBarController *)self.window.rootViewController;
        [MyTabViewController setSelectedIndex:3];
        WelcomeHomeViewController *welcomeHomeViewController = [[MyTabViewController viewControllers] objectAtIndex:3];
        [welcomeHomeViewController viewDidLoad];
        //Need help here I think  - Anyway to hide MyTabViewController when its presented?
     }

}

I have been through a lot of threads and the things that keeps popping up are:

 //[MyTabViewController presentModalViewController:WelcomeHomeViewController animated:YES];
 //self.navigationController.navigationBarHidden = YES;
 //[self setHidesBottomBarWhenPushed:YES];

I have tried many different places with these and probably just need to step back and relax but I can't find the solution right now. Also to note this is not in an UITableView. Any help would be greatly appreciated and I always mark my questions answered when answered.


Solution

  • Ok, here is what I put in the if statement:

        UITabBarController *MyTabViewController = (UITabBarController *)self.window.rootViewController;
    
        [MyTabViewController setSelectedIndex:3];
        UINavigationController *welcomeHomeViewController = [[MyTabViewController viewControllers] objectAtIndex:3];
                UITabBar *tabBar = MyTabViewController.tabBar;
        tabBar.hidden = YES;
        [welcomeHomeViewController viewDidLoad];
    

    This does seem off to me, please let me know if there is a better way. Just wanted to post the answer incase anyone else can be helped from this.

    EDIT:The bar is still visible :( , but there are no buttons to push, just a black strip. Any help would be appreciated. At least the user can't access the bar, but I need to hide it eventually.

    Edit:OK FINALLY!! So glad I have this solved and really hope this can help others!

    Here it is, modified in appsdevs post here: How to Hide Tab Bar Controller?

    UITabBarController *MyTabViewController = (UITabBarController *)self.window.rootViewController;
    
        for(UIView *view in MyTabViewController.view.subviews)
        {
            if([view isKindOfClass:[UITabBar class]])
            {
                [view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
            } else 
            {
              [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
            }
        }
    
        [MyTabViewController setSelectedIndex:3];
        UINavigationController *welcomeHomeViewController = [[MyTabViewController viewControllers] objectAtIndex:3];
    
        [welcomeHomeViewController viewDidLoad];