07-18-2023, 07:29 PM
You need to implement the **UISearchBarDelegate**.
The `UISearchBarDelegate` protocol defines the optional methods you implement to make a `UISearchBar` control functional. A `UISearchBar` object provides the user interface for a search field on a bar, but it’s the application’s responsibility to implement the actions when buttons are tapped. At a minimum, the `delegate` needs to perform the actual search when text is entered in the `textField`. [Read this][1]
**In Objective C**
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
[self.searchDisplayController setActive:NO animated:YES];
}
**In Swift :**
func searchBarCancelButtonClicked(searchBar: UISearchBar) {
self.searchDisplayController.setActive(false, animated: true)
}
[1]:
The `UISearchBarDelegate` protocol defines the optional methods you implement to make a `UISearchBar` control functional. A `UISearchBar` object provides the user interface for a search field on a bar, but it’s the application’s responsibility to implement the actions when buttons are tapped. At a minimum, the `delegate` needs to perform the actual search when text is entered in the `textField`. [Read this][1]
**In Objective C**
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
[self.searchDisplayController setActive:NO animated:YES];
}
**In Swift :**
func searchBarCancelButtonClicked(searchBar: UISearchBar) {
self.searchDisplayController.setActive(false, animated: true)
}
[1]:
[To see links please register here]