I need a tableview to be presented modally after user taps on the search bar, and then be able to have the tableview present things the user searched, like Instagram's search function. There are plenty of tutorials on google about how to make a search feature, but none about how to present a tableview after the user taps on the search bar. How should I do that?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
To make the search results of a UISearchController
appear in a new UITableView
of your choice, do this:
let searchController = UISearchController(searchResultsController: myTableViewController)
instead of this:
let searchController = UISearchController(searchResultsController: nil)
Passing a view controller to the constructor allows the UISearchController
to display the view controller at appropriate times (i.e. when the search is active). This is what you need to do.
Passing nil
means, I'm using my own view controller (and table view).