Swift ios11 NavigationItem SearchBar won't hide completely

Viewed 979

Having an issue with adding a search controller to a navigationItem in iOS11 / Swift 4.

Basically everything works as expected for the most part, pull down will reveal the search bar and searching works fine. However when trying to hide the search bar by scroll back up... the bar won't hide completely and remains as a thin strip (see below).

I have declared my search controller as follows:

let searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.scopeButtonTitles = ["All", "Samples"]
searchController.searchBar.delegate = self
navigationItem.searchController = searchController

Before (scroll down to reveal search bar):

enter image description here

After (scroll up to hide):

enter image description here

3 Answers

In my case it was happening only when there was a small num of items in the table. I came to a non-technical, but rather a logical solution to show the search bar only when there are >10 items in the list. There is no need to have search when you have only a few items anyway.

Related