I have a UIViewController that I open by presenting it. In it avec have just a UITableView and UISearchController that :
let searchController = UISearchController(searchResultsController: nil)
if #available(iOS 11.0, *) {
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = false
definesPresentationContext = true
}
It works well. I can filter the UITableView each time the user update the UISearchBar field.
My func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) function is like that :
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
dismiss(animated: true, completion: nil)
}
The first time I select a row after filtering the UItableView (when the UISearchBar is focused) my func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) is called but the dismiss(animated: true, completion: nil) does not work. It just resignFristResponder() the UISearchBar.
Then if a select again a cell, now that the UISearchBar is no more focused the dismiss(animated: true, completion: nil) works.
So I have to select twice a cell to see my UIViewController dismissed.
What is wrong with that ?