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
class MyController: UIViewController, UISearchBarDelegate {
// Called when search bar obtains focus. I.e., user taps
// on the search bar to enter text.
func searchBarTextDidBeginEditing(searchBar: UISearchBar) {
searchBar.showsCancelButton = true
}
func searchBarCancelButtonClicked(searchBar: UISearchBar) {
searchBar.text = nil
searchBar.showsCancelButton = false
// Remove focus from the search bar.
searchBar.endEditing(true)
// Perform any necessary work. E.g., repopulating a table view
// if the search bar performs filtering.
}
}