searchresultcontroller

searchresultcontroller

我想有一个单独的viewController作为searchresultcontroller,但是,我得到了不寻常的行为说明如下。
我正在设置searchController;

func setUpSearchControllerAttributes() {
    searchController = UISearchController(searchResultsController: searchResultsController)
    searchController.delegate = searchResultsController
    searchController.definesPresentationContext = true
    searchController.hidesNavigationBarDuringPresentation = false
    searchController.dimsBackgroundDuringPresentation = false
    searchController.searchBar.sizeToFit()
    searchController.searchBar.backgroundColor = .white
    searchController.searchBar.barTintColor = .white
    searchController.searchBar.placeholder = "Search"
    searchController.searchBar.searchBarStyle = .minimal
}

当我加上:
navigationItem.titleView = searchController.searchBar

我得到:
swift - SearchResultsController出现在UINavigationBar上-LMLPHP
为了便于说明,我已将searchresultcontroller视图颜色设置为.green和低alpha。
如您所见,searchresultcontroller与导航栏重叠。
现在当我设定:
navigationItem.searchController = searchController

结果如下:
swift - SearchResultsController出现在UINavigationBar上-LMLPHP
对此有什么解释吗。显然,问题在于将searchresultcontroller搜索栏设置为navigationItem文本视图。

最佳答案

我有;

searchController.definesPresentationContext = true

需要被取代的;
self.definesPresentationContext = true

关于swift - SearchResultsController出现在UINavigationBar上,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51466151/

10-14 21:25