I'm having a weird issue where when I click the "x" in the search bar to clear the text field, it registers as a gesture on the Cancel/Done button and dismisses the view (see gif in link below). But when I click a few points to the left of the clear button, it performs the desired action of clearing the text field. Below is my code to configure the search bar table view
https://giphy.com/gifs/oXA94eUOyaVTW
func presentSearchBarViews() {
searchController.searchBar.sizeToFit()
tableView.tableHeaderView = searchController.searchBar
tableView.tableFooterView = UIView()
if #available(iOS 9.0, *) {
searchController.searchBar.setValue("Done", forKey:"_cancelButtonText")
searchController.searchBar.placeholder = "Search for food"
searchController.searchBar.showsCancelButton = true
searchController.searchBar.layer.borderWidth = 1;
searchController.searchBar.layer.borderColor = UIColor.init(red: 0.45, green: 0.78, blue: 0.77, alpha: 1.0).CGColor
searchController.searchBar.delegate = self
}
I'm pretty stumped on how to solve this one since I'm configuring the search bar programmatically. Any help is much appreciated!
UPDATE
Setting searchController.searchBar.showsCancelButton = false
doesn't seem to get rid of the Done/Cancel button like it should. What could possible be the cause of this?