user25917
user25917

Reputation: 977

How can I prevent UISearchController dismiss when cancel button pressed?

I want to just hide keyboard when user first press cancel button.
Just likes AppStore.app

I use UISearchController like that:

    navigationItem.searchController = searchController

============== Update ==============
This Cancel button is hosted by UISearchController.

Upvotes: 1

Views: 467

Answers (1)

AzeTech
AzeTech

Reputation: 707

If you did search bar programmatically, you can add extension on your ViewController or else just use function call as below.

 extension ViewController: UISearchBarDelegate {
     func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
         if let text = searchBar.text {
             self.filterContent(text: text)
             searchBar.resignFirstResponder()
         }
     }
 }

Upvotes: 1

Related Questions