How to show tableview when user taps searchbar swift

前端 未结 1 786
闹比i
闹比i 2020-12-19 14:51

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 sear

相关标签:
1条回答
  • 2020-12-19 15:01

    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).

    0 讨论(0)
提交回复
热议问题