3

I am stuck in a problem many people experienced here before, but solutions to it mutate in time, as new iOS releases come up and APIs change. None of the previous solutions work for my present setup - XCode 4.2.1, iPhone simulator 5.0 or real iPhone 5.0, app targets iOS5, using ARC and Storyboard.

I have a classic Tabbed app -ie UITabBarController, in it 4 tabs...ignore the 2 to 4th tab.. The first tab hosts a UINavigationController with its rootviewcontroller being a UITableViewController. Now I am pushing 1 CustomUIViewController onto the stack.

The whole setup is visualy designed in Storyboard, the push is done by a segue.

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    self.hidesBottomBarWhenPushed = YES;
}

This effectively hides the tabbar exactly the same way as the iPod app does in iPhone.

But when i pop the CustomUIViewController from the stack, the TabBar does not come back. I was putting the

self.hidesBottomBarWhenPushed = NO;

to all possible and impossible places, but with no luck.

HOW can I bring my TabBar back?

WrightsCS
  • 50,551
  • 22
  • 134
  • 186
Earl Grey
  • 7,426
  • 6
  • 39
  • 59

4 Answers4

7

This is a sumarized answer, to provide future readers a clean readable solution and formulate some related issues explicitely.


The solution to the problem is the following code>

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    [segue.destinationViewController setHidesBottomBarWhenPushed:YES];
}

The problem/confusion lies in the fact, that in theprepareForSegue: method, it is possible to set the property "hidesBottomBarWhenPushed" on the source view controller (the one we see right at the moment) or on the destination view controller (the one that is being pushed onto the stack). By setting this either way, you get the first half of the problem solved ie. your TabBar gets hidden. This is why the "hiding" part in my former code worked, I was setting the property on the source viewcontroller. In my code

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    self.hidesBottomBarWhenPushed = YES;
}

here, "self" points to the source view controller, not the destionation view controller. So we must set this to the destination view controller...

One last issue .. this code with dot notation does not work>

segue.destinationViewController.setHidesBottomBarWhenPushed = YES;

You mut call the setter method like this

[segue.destinationViewController setHidesBottomBarWhenPushed:YES];

The solution is exactly according to the Apple specification, that states "the bottom bar remains hidden until the view controller (that has the hide property set to YES) is popped from the stack."

Last thing, do not forget to narrow down the setting of the hide property to a speficic segue

-(void)prepareForSegue:(UIStoryboardSegue *)segue 
                sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"SegueIdentifier"]) 
    {
        [segue.destinationViewController setHidesBottomBarWhenPushed:YES];
    }
}

I am splitting the reward for two users (bounty goes to Ash Furrow, accepted solution to Eric Lars0n, this is the closest I could come after reading the rules about bounties and acceptances) who both helped me solve this, + a small comment why, in their respected threads.

Earl Grey
  • 7,426
  • 6
  • 39
  • 59
5

I think you need to set

segue.destinationViewController.hidesBottomBarWhenPushed = YES;

instead of self.hides....

agilityvision
  • 7,901
  • 2
  • 29
  • 28
4

According to Apple, "the bottom bar remains hidden until the view controller is popped from the stack." There is no way to "unhide" the bottom bar unless you pop to a view controller higher up in the navigation hierarchy.

You'll have to come up with some other workaround that doesn't involve the hidesBottomBarWhenPushed property. There's a good description of how to accomplish this in another SO question.

Community
  • 1
  • 1
Ash Furrow
  • 12,391
  • 3
  • 57
  • 92
  • 1
    After I almost lost hope, your comment led me to inspect where the "self" actually points, and realize that I cannot pop the source controller and thus try again the solution from Eric Lars0n. – Earl Grey Jan 02 '12 at 20:47
1

Just put [segue.destinationViewController setHidesBottomBarWhenPushed:YES]; in prepareForSegue.

For me works fine.

GDP
  • 8,109
  • 6
  • 45
  • 82
cesc
  • 11
  • 1