Reputation: 2826
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?
Upvotes: 4
Views: 2597
Reputation: 1058
Try this
searchController.active = false
or swift 4+
searchController.isActive = false
Upvotes: 0
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