views:

927

answers:

1

Hi there,

When you enter the search bar handled by a search display controller, it slides the view up and pushes the navigation bar up with it. This is easy enough to do, however, when you click a search result and a new view is pushed on the navigation controller's stack, the navigation bar slides in from the right with the view!

How is this done? If you simply set the navigation bar to hidden or shown, it happens instantly. I can't figure out how it seems to be hidden just for one view controller in the stack!

Many thanks,

Michael

+2  A: 

You can animate the transition of the navigation bar. See -setNavigationBarHidden:animated: for more details.

If you need to do this on a per-view controller basis, just override the view controller's -viewDidAppear: and -viewWillDisappear: methods, e.g.:

- (void) viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

- (void) viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

The above will hide the navigation bar when this view controller is pushed on top of the navigation stack, and show the navigation bar when the view controller is popped off.

You can call -setNavigationBarHidden:animated: whenever you want, but those two methods are useful for applying lots of UI changes.

Alex Reynolds
Yes but that will hide the navigation bar from then on, and when you push another view controller it will still be hidden. And even if you show the navigation bar as you push the new controller, you will see the navigation appear on the previous controller. This is because the navigation bar is the same bar for all the controllers on the navigation controller's stack. Hence being confused as to how the search display controller does what it does!
Michael Waterfall
See edited answer. You can animate the navigation bar as the view controller is pushed/popped.
Alex Reynolds
Ahhh no way! Genius! I had no idea putting the show/hide code in the viewWillAppear/Disappear would make any difference as to how the navigation bar was displayed! Thanks ever so much, I was stumped for quite a few hours on this one!
Michael Waterfall