Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activating search bar doesn't hide navigation bar

I have an iOS 7 application in XCode 5.0 that exhibits some strange behavior when tapping the search bar (UISearchBar).

My application has a Navigation Controller, and a Tab Bar Controller. Here is an example of what my Main.Storyboard looks like:

[Navigation Controller] -> [Tab Bar Controller] -> [Tab Item #1]
                                    |
                                    -------------> [Tab Item #2]

Each [] is a view controller

When I launch my application, I see the Tab Item 1 with the UISearchBar as shown in the screenshot below:

one

When I tap the UISearchBar, the search bar slides up to the top of the screen, but the Navigation Bar does not hide, and the view does not "slide up". This causes the app to look like this:

two

When I delete the Tab Bar Controller from the storyboard and connect the Navigation Controller directly to Tab Item #1 the Navigation Bar hides as expected.

How can I make the Navigation Bar hide when tapping the Search Bar? For an example of the functionality I am looking to reproduce, click the search bar under the "Contacts" tab of the default iOS7 "Phone" application.

like image 287
Ian Avatar asked Oct 13 '13 18:10

Ian


People also ask

How do I make my navigation bar hidden?

Way 1: Touch “Settings” -> “Display” -> “Navigation bar” -> “Buttons” -> “Button layout”. Choose the pattern in “Hide navigation bar” -> When the app opens, the navigation bar will be automatically hidden and you can swipe up from the bottom corner of the screen to show it.

Where is the navigation bar on my computer?

When referring to a web page, a navigation bar is a graphical bar located at the top of a page. It is used to link users to other main portions of a website.

What is the function of navigation bar?

A navigation bar helps readers in selecting topics, links or sub-topics of their interest. Using a navigation bar, users need not enter the URL of the specific webpage, as this is automatically taken care of by the navigation bar, with the navigation sections having embedded the necessary links of the webpage.


1 Answers

For swift developers:

func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) { 

  navigationController?.setNavigationBarHidden(true, animated: true)

}

func searchBarTextDidEndEditing(_ searchBar: UISearchBar) { 

  navigationController?.setNavigationBarHidden(false, animated: true)

}

This will hide the navigation bar while search bar is active and show it again when search bar is inactive.

like image 99
Rubaiyat Jahan Mumu Avatar answered Sep 20 '22 11:09

Rubaiyat Jahan Mumu