UISearchController没有显示

时间:2017-05-10 13:23:20

标签: ios swift swift3 uisearchcontroller

我正在使用Swift 3.1,我想要一个简单的搜索功能,搜索结果将以搜索栏下方的popOver方式显示。这是本机产品,应该可以使用UISearchController。但即使经过我的反复试验,我也无法做到这一点。我错过了什么吗?

我已经提到过resultsController。实现了所需的代表,甚至是我们提供给它的数据。但仍未显示。

任何帮助将不胜感激。感谢。

代码:

    func initiateView() {
    resultsController = ResultsController()
    resultsController.table.dataSource   =   self

    searchController   =   UISearchController.init(searchResultsController: resultsController)
    self.view.addSubview(searchController.searchBar)
    searchController.searchResultsUpdater   =   self

    searchController.delegate = self
    searchController.dimsBackgroundDuringPresentation = false // default is YES
    searchController.searchBar.delegate = self    // so we can monitor text changes + others
    definesPresentationContext = true


    feedTable   =   UITableView()
    feedTable.delegate  =   self
    feedTable.dataSource    =   self
    feedTable.separatorStyle    =   .singleLineEtched
    feedTable.register(UITableViewCell.self, forCellReuseIdentifier: "SomeCell")
    self.view.addSubview(feedTable)


    feedTable.pinToSuperview([.Left, .Right, .Bottom])
    feedTable.pinToSuperviewTop(withInset: 50, priority: 100)
}


func updateSearchResults(for searchController: UISearchController)
{
    if let searchString = searchController.searchBar.text{
        let resultsController = searchController.searchResultsController as! ResultsController
        resultsController.resultsArray  =   feedArray.filter({$0 .contains(searchString)})
        resultsController.table.reloadData()
    }
}

0 个答案:

没有答案