0

我正在使用UISearchController(不是UISearchDisplayController),我想在搜索處於活動狀態時顯示單獨的視圖。我不想使用當前視圖。如何在UISearchController中顯示不同的searchResultsController

試用self.searchController = UISearchController(searchResultsController: self.resultsController)。但是這並沒有表現出什麼。

即使想這

func presentSearchController(_ searchController: UISearchController) { 
    DispatchQueue.main.async { 
     searchController.searchResultsController?.view.isHidden = false 
    } 
} 

func didPresentSearchController(_ searchController: UISearchController) { 
    searchController.searchResultsController?.view.isHidden = false 
} 

我的默認表數據之前,搜索是積極的,如下,我想這個表格來隱藏和顯示不同的視圖和輸入關鍵字傳遞給新的看法。我怎樣才能做到這一點?

enter image description here

回答

1

由於沒有直接順着接下去的viewController,我們需要明確的是指我們要使用的viewController。

我已經使用了下面的代碼,當我的searchBar處於活動狀態時,它加載了我的新控制器。

let storyboard = UIStoryboard(name: "Main", bundle: nil) 
    self.resultsController = storyboard.instantiateViewController(withIdentifier: "searchResults") as! SearchResultsTableViewController 
    self.searchController = UISearchController(searchResultsController: self.resultsController) 

讓我知道是否有更好的方法可用。

相關問題