Search code examples
iosobjective-ccocoa-touchuitabbarcontrolleruitabbar

Hiding custom UITabBar


I have successfully created and implemented a custom UITabBarController with a custom UITabBar following this tutorial. It works fine until I have to hide it.

I'm not using Storyboards or IB and I have to get a reference to my existing UITabBarController which is on screen to hide a custom UIView in it. I'm trying to do it this way but it's only creating a new instance of that UITabBarController and not pointing me to the original instance I see onscreen:

SGTabBarController *tabBarController = [[SGTabBarController alloc] init];
[tabBarController hideCustomTabBar];

SGTabBarController.h

@interface SGTabBarController : UITabBarController

@property (nonatomic) int tabBarHeight;

-(void)hideCustomTabBar;
-(void)showCustomTabBar;

@end

SGTabBarController.m

-(void)hideCustomTabBar{
    customTabBarView.hidden = YES;
    NSLog(@"HIDDEN!!!");
}

-(void)showCustomTabBar{
    customTabBarView.hidden = NO;
}

Any ideas on how to get to it? Thanks in advance!


Solution

  • How I am able to access a custom UITabBarController anywhere in the app.

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    // Set up the Dashboard
    //
    _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [_window makeKeyAndVisible];
    
    UITabBarController *tabBarController = [[UITabBarController alloc] init];
    NSMutableArray *tabBarItems = [@[] mutableCopy];
    
    // Repeat this for any amount of ViewControllers
    UITableViewController *tableViewController = [UITableViewController alloc] initWithStyle:UITableViewStylePlain];
    UINavigationController *navController = [UINavigationController alloc] initWithRootViewController:tableViewController];
    
    [tabBarItems addObject:navController];
    tabBarController.viewControllers = tabBarItems;
    self.window.rootViewController = tabBarController;
    
    return YES;
    }