如何使用SearchResultsController实现SearchController

时间:2017-10-31 15:49:39

标签: ios swift uisearchcontroller

您好我正在尝试将SearchController实现到我的应用程序中,但是,我的应用程序有不同的选项卡,我希望它们能够看到搜索功能。我在NavBar中添加了一个按钮,每个选项卡都有一个包含此代码的主控制器视图。不幸的是,当我尝试搜索某些内容时,表格视图不会显示结果。谢谢您的帮助!请找到以下代码:

MainController:

// set up search:
func setUpSearch(){
self.searchDataSource = DataTableViewController() // UIViewController, contains all functions for tableview plus outlet of tableview
self.searchController = UISearchController.init(searchResultsController: searchDataSource)
self.searchController?.searchBar.delegate = self
         self.searchController?.searchBar.showsCancelButton = true
         self.searchController?.searchBar.placeholder = "Search for people or places"
}


// user clicked on search button:
func searchButtonClicked(){
    self.searchController?.isActive = true
    self.searchController?.searchBar.becomeFirstResponder()
    if let controller = self.searchController {
        present(controller, animated: true, completion: nil)
    }
}

0 个答案:

没有答案