Check if tabBar is visible on iOS app

ValentiGoClimb picture ValentiGoClimb · Aug 13, 2013 · Viewed 8.4k times · Source

I am working on an iOS App that have an UITabBarController for show a TabBar. In some where, I present a modalView full screen that hides the tabBar.

I want to detect when my tabBar is visible for the user. There is any way to check automatically when de tabBar is visible or not?

I tried that:

But it really don't work because the tabBar is not really hidden.

if ([[[appdelegate tabBarController] tabBar] isHidden])
{
    NSLog(@"tabBar IS HIDDEN");
}
else
{
    NSLog(@"tabBar IS VISIBLE");
}

I write this code in a BaseViewController which is super class of my modal view and the other views of my project.

Thanks.

Answer

Julian Król picture Julian Król · May 26, 2014

Checking this [[[self tabBarController] tabBar] isHidden] is fine but in one case it will fail. If you do not have tab bar in that view (at all) then [self tabBarController] returns nil so calling isHidden will return NO which is the truth but you have to detect that situation that it is other case. It is not hidden but it doesn't exits so, except that checking you should add [self tabBarController] != nil. So basically:

if([self tabBarController] && ![[[self tabBarController] tabBar] isHidden]){
    //is visible
} else {
    //is not visible or do not exists so is not visible
}