I have a search bar with cancel button. But when I click on Cancel button it doesn\'t close the search bar. How can I make that on click on Cancel it will return search bar to t
Very quick and simple. Just conform to the UISearchBarDelegate protocol, and then implement this function in your class:
func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
searchBar.resignFirstResponder()
}
resign means that it will quit
FirstResponder is the focus of the view
In conclusion, this takes focus away from the search bar, effectively canceling it.