I'm facing a few problems with UISearchController under iOS 13.
I'm using a UISearchController within a UITableViewController in order to search for something within the table.
The first problem occurs if the TableView only has a few items, so that there's a lot of unused room at the bottom of the TableView. When the UITableViewController is shown, the search field is hidden, just as it is supposed to. But once I start scrolling to make the search field visible, it is absoultley impossibel to scroll back in order to hide the search field again. This only works if there are more cells in the table that will fit on screen. This doesn't look very nice. This issue occurs on both iPad and iPhone.
Is there a way to hide the search field by scrolling again, just like it is supposed to work and like it is working when enough cells are available?
The second problem is a big one and occurs if I set a darker barTintColor for the navigation toolbar (and a bright or white tint color to the navigation toolbar buttons and texts). Whenever I scroll down to reveal the search field, the whole navigation toolbar (including the area with the search field) will change its color and will get the color of the background color of the TableView (usually white or light gray for the "grouped" tables). This makes the search field, the icons and title of the navigation toolbar totally unreadable, because they still have the same bright/white color as before.
I thought that this might be intended behavior when the searchBar.searchBarStyle property is set to .minimal, but this doesnät seem to be the case, because it also happens when using .prominent.
This issue only occurs on the iPad, but not on the iPhone
Is there a way to make sure that the navigation toolbar does not change its color when scrolling the search field into view? With using the default colors (white navigation bar) this is not a big deal and hardly noticable, but with other colors this can get ugly.
BTW: the issue with the colors does not happen in the simulator, only on a real device. But this might be because of the iOS release: the simulator only supports iOS 13.0, while the real device uses iOS 13.1.3. Sothis might be one of the many new bugs of iOS 13
This is how I create the UISearchController:
override func viewDidLoad() {
super.viewDidLoad()
searchController = UISearchController(searchResultsController: nil)
searchController?.hidesNavigationBarDuringPresentation = false
searchController?.dimsBackgroundDuringPresentation = false
searchController?.obscuresBackgroundDuringPresentation = false
searchController?.searchResultsUpdater = self
searchController?.searchBar.searchBarStyle = .prominent
navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = true
Both of the above issues do look extremly ugly, so my current "workaround" is to always show the search field (using navigationItem.hidesSearchBarWhenScrolling = false). This is not really what I want, but at least it doesn't look as ugly.