Nevin Jethmalani
Nevin Jethmalani

Reputation: 2826

Hide Search Bar Controller Manually

How do I hide the search bar controller manually when it is in the navigation bar in iOS 11? I have tried a few things but they don't work. I have included an image of the search bar I have setup. I want it to go back to being the normal navigation controller it generally is before I pull down to show the search bar. It seems like a single line of code that I am missing but I for some reason just cannot find that line of code. I want this to happen on view did appear so anytime a user comes back to this screen, the search bar is hidden. How do I do that?

Before enter image description here

As I am scrolling up enter image description here

Upvotes: 4

Views: 2597

Answers (2)

shivi_shub
shivi_shub

Reputation: 1058

Try this

searchController.active = false

or swift 4+

searchController.isActive = false

Upvotes: 0

Abdulaziz.Musaileekh
Abdulaziz.Musaileekh

Reputation: 325

Swift

To hide the searchBar use

navigationItem.searchController = nil

To show again the searchBar use

navigationItem.searchController = searchController

where searchController is the UISearchController of your controller

Upvotes: 1

Related Questions