0

I have two UIViewControllers within a UINavigationController. The topmost has hidesBottomBarWhenPushed set to YES. When I push the topmost UIViewController, its UITableView is pushed about 20px above where it should be (notice the difference in cell height between the top to cells of the pushed view controller).

Push UIViewController, Hide UIToolBar

Compare to in cell position in the screenshot below:

Pushed UIViewController, Hidden UIToolBar

Additionally, when I pop the topmost UIViewController, its UITableView is pushed about 20px below where it should be (notice the extra dark blue space above the UITableView).

enter image description here

I've tried moving my -[UIViewController setHidesBottomBarWhenPushed:YES] calls into -[UIViewController loadView], -[UIViewController viewWillAppear:], and -[UIViewController viewDidAppear:]. Those callbacks are all too late because the UIViewController has already been pushed, so the UIToolbar is not hidden.

Is there any way to avoid these gaps? Presently, I'm calling -[UINavigationController setToolbarHidden:YES animated:NO] in my topmost UIViewController's -[UIViewController viewDidAppear:] and -[UINavigationController setToolbarHidden:NO animated:NO] in my bottommost UIViewController's -[UIViewController viewDidAppear:]. This is less than ideal.

Heath Borders
  • 30,998
  • 16
  • 147
  • 256

1 Answers1

0

Let's say A pushes B. From your description, it sounds like B shouldn't have to know that whatever presented it had a toolbar. Rather, when A pushes a B, A knows B shouldn't have A's toolbar. So why wouldn't you just set it when you init B?

BController *b = [[BController alloc] init];
b.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:b animated:YES];

Alternatively, if you think B does need to control this behavior, you could put it in B's init method.

Christopher Pickslay
  • 17,523
  • 6
  • 79
  • 92