简体   繁体   中英

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.

根据文档,更改搜索控制器的active属性会将搜索栏移动到导航栏

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM