UISearchController 不使用导航控制器

Cod*_*dey 5 iphone uinavigationcontroller uisearchbar swift uisearchcontroller

是否可以使用UISearchController而不SearchBar显示在 中Navigation Controller?我基本上希望SearchBar保留在屏幕上并在其下方显示 TableView:

小样

我想做的是:我UITableViewController在故事板上创建了一个并将其链接到自定义NPTableViewController类。然后我这样做了:

    let resultsTable = storyboard!.instantiateViewController(withIdentifier: "LocationSearch") as! NPTableViewController
    searchController = UISearchController(searchResultsController: resultsTable)
    searchController?.searchResultsUpdater = resultsTable

    let searchBar = searchController!.searchBar
    searchBar.sizeToFit()
    searchBar.placeholder = "Search for places"
    searchBar.frame.origin.y = 100.0
    self.view.addSubview(searchBar)
Run Code Online (Sandbox Code Playgroud)

现在,当我运行它时,会searchBar显示 ,但是当我单击它时,背景会变暗,searchBar消失,我的resultsTable也不显示。

Cod*_*dey 4

我想出的解决方案实际上非常简单。我没有使用UISearchController,而是使用了普通的UISeachBarUITableView。由于对UISearchController您没有太多帮助,因此如果我构建自己的 SearchController,工作几乎是相同的。