1

My app hide the navigationbar in the beginning.

But in a view(full screen), there is a search bar.

when I begin to search, the search bar stays in the top of the view.

Then I cancel the search,change the search bar's frame,the navigationbar appears.

Why does this happen? how can I hide the navigation bar ?

I tried this:

I add some logs in searchDisplayControllerWillEndSearch and searchDisplayControllerDidEndSearch to show navigtaionbar status.

In searchDisplayControllerDidEndSearch, navigationController.navigationBarHidden is YES,

In searchDisplayControllerDidEndSearch, navigationController.navigationBarHidden is NO.

Then I set navigationController.navigationBarHidden to YES in searchDisplayControllerDidEndSearch,The navigation bar will show but hide in a short time,and navigation bar will never show again.(navigationController.navigationBarHidden will always be YES)

Any ideas?

Thanks!

Community
  • 1
  • 1
Cotin
  • 11
  • 3

3 Answers3

0

Write following code in ViewDidLoad Method.

self.navigationController.navigationBarHidden =YES

Other Wise

self.navigationController.navigationBar.hidden =YES;
Maulik shah
  • 1,664
  • 1
  • 19
  • 45
  • I set self.navigationController.navigationBar.hidden to YES in searchDisplayControllerDidEndSearch, it works.But at first time, the navigation bar will show first, then hide immediately,seems too weird.Is there any way to hide navigation bar and user won't see it. – Cotin Sep 25 '14 at 05:19
0

I have already found a similar question here: UISearchBar with hidden UINavigationBar

And the solution: IPHONE: ABPeoplePickerNavigationController hidden navigation bar

Community
  • 1
  • 1
Cotin
  • 11
  • 3
-1
  • you can use the following code in your viewDidLoad to hide the navigation bar Self.navigationController.navigationBar.hidden = YES;

  • if you are presenting the navigation controller then you can hide your navigationbar before presenting, by using this code yournavigation.navigaionBar.hidden = YES;

  • we can use either of the code to hide navigation bar self.navigationController.navigationBarHidden = YES;

    or

    Self.navigationController.navigationBar.hidden = YES;

  • Final one it may solve your problem hide navigation bar in viewWillAppear. Here i am adding code

    - (void)viewWillAppear:(BOOL)animated { self.navigationController.navigationBar.hidden = YES; [super viewWillAppear:animated]; }

Anjaneyulu Battula
  • 1,910
  • 16
  • 33
  • You should never use navigationController.navigationBar.hidden - use navigationController.navigationBarHidden – Simon Sep 25 '14 at 07:53
  • First, thanks for your answer.If I use navigationController.navigationBar.hidden,and set to YES,there will be a black space in the top,seems the navigationbar still use this space. – Cotin Sep 25 '14 at 09:18
  • @Simon Hi Simon but just now i checked both codes both are working fine nd if is there any reason to do not use navigationController.navigationBar.hidden , can you please explain little more? – Anjaneyulu Battula Sep 25 '14 at 09:42
  • The UINavigationController controls the navigation bar. If you use navigationController.navigationBar.hidden then at a later point the navigation controller will show or hide it to match what it wants; whereas if you use navigationController.navigationBarHidden then the controller will show or hide it according to what you want. – Simon Sep 25 '14 at 09:42
  • @simon Okay thanks for your information and I modified my answer also. – Anjaneyulu Battula Sep 25 '14 at 11:34