Jaume
Jaume

Reputation: 923

xcode unable to hide tabbarcontroller

I have a tabbarcontroller as main controller and when a view is pushed I would like to hide it. I use hidesBottomBarWhenPushed but not working. Thanks.

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.hidesBottomBarWhenPushed = YES;
    }
    return self;
}

Upvotes: 1

Views: 1289

Answers (3)

daveoncode
daveoncode

Reputation: 19578

I've implemented my own custom tabBarController (which extends the original UITabBarController), because I need to toggle bars programmatically under certain circumstances (like device rotation), this is my implementation (comments explain how it works):

- (void)hideBottomBar:(BOOL)hide
{
    @try 
    {
        // UITabBarController has 2 subviews:
        // - the first (index:0) is that one containing the active view controller's view
        // - the second (index:1) is that one containing the UITabBar (self.tabBar)
        UIView *topView = [self.view.subviews objectAtIndex:0];
        UIView *bottomView = [self.view.subviews objectAtIndex:1];

        // hide tabs container if necessary
        [bottomView setHidden:hide];

        // adjust frame
        if (hide) 
        {
            // expand main view to fit available space
            [topView setFrame:self.view.bounds];
        }
        else
        {
            // restore main view frame
            CGRect frame = topView.frame;
            frame.size.height -= bottomView.frame.size.height;
            [topView setFrame:frame];
        }
    }
    @catch (NSException *exception) 
    {
        [[GTMLogger sharedLogger] logError:@"Error occured adjusting tabs view: %@", exception.description];
    }
}

Upvotes: 0

shannoga
shannoga

Reputation: 19869

try to add this line when you push this controller, in it's parent view controller :

    YourViewController *controller = [[YourViewController alloc]init....];
    controller.hidesBottomBarWhenPushed = YES;
    //then push the view controller

Good Luck

Upvotes: 2

Felix Lamouroux
Felix Lamouroux

Reputation: 7484

This will only work if one of the viewControllers of the tabBarController is a UINavigationController. The hidesBottomBarWhenPushed property is only respected if a view controller is pushed onto the stack of a UINavigationController and will not do much if it is the root view controller.

Upvotes: 1

Related Questions