tim
tim

Reputation: 173

UISearchBarDelegate function -searchBarSearchButtonClicked not working

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

Answers (2)

Bala AP
Bala AP

Reputation: 37

Please take outlet for your searchbar and confirm delegate.

yoursearchbar.delegate = self

Thanks

Upvotes: 1

Maddy
Maddy

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.

enter image description here

Upvotes: 1

Related Questions