Reputation: 977
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
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