Reputation: 173
I am trying to use a delegate function searchBarSearchButtonClicked from UISearchBarDelegate. My search bar is located in the header of UITableViewController. Please can someone advise?
class MySearchTableViewController: UITableViewController, UISearchBarDelegate{
override func viewDidLoad() {
super.viewDidLoad()
}
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
print("clicked!")
}
}
Upvotes: 1
Views: 803
Reputation: 37
Please take outlet for your searchbar and confirm delegate.
yoursearchbar.delegate = self
Thanks
Upvotes: 1
Reputation: 1668
You need to set the delegate of search bar.
(1) mySearchBar.delegate = self
(2) In storyboard, ctrl+drag the search bar to the viewController and choosing delegate.
Upvotes: 1