-
Notifications
You must be signed in to change notification settings - Fork 3
iOS UISearchBar
Kevin Leong edited this page Oct 13, 2016
·
2 revisions
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
// Removes focus from the search bar.
searchBar.endEditing(true)
// Perform any necessary work. E.g., repopulating a table view
// if the search bar performs filtering.
}
}