Imran
Imran

Reputation: 779

iOS: how to add a search bar on navigation bar programmatically on a button press?

I know how to initialise the UIsearchcontroller by doing this:

let searchResultsController = UITableViewController(style: .Plain) as UITableViewController
searchResultsController.tableView.delegate = self
searchResultsController.tableView.dataSource = self
searchController = UISearchController(searchResultsController: searchResultsController)

so, I have a button on navigation bar and on press I want to display SearchBar using UISearchController and then dismiss the search bar on tapping again on the search button or empty space of screen.

Upvotes: 1

Views: 1616

Answers (1)

Pr0Ger
Pr0Ger

Reputation: 538

According to documentation, changing active property of search controller will move search bar to navigation bar

Upvotes: 0

Related Questions