带有UITableViewController的searchResultsController隐藏了导航栏,如何防止它?

时间:2017-09-30 22:28:17

标签: ios swift ios11

当我将TableViewController指定为UISearchController的构造函数时,当加载表时,它会隐藏导航栏(包括标题和搜索栏)。我该怎么做呢,所以它不会隐藏它?

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        configureNavigationItem()
    }
}

extension ViewController {

    private func configureNavigationItem() {
        let resultsController =  UITableViewController(style: .plain)
        navigationItem.searchController = UISearchController(searchResultsController: resultsController)
        navigationItem.hidesSearchBarWhenScrolling = false
    }
}

Initial Load

enter image description here

Tap Any Key

enter image description here

1 个答案:

答案 0 :(得分:2)

找到答案:

definesPresentationContext = true

如:

private func configureNavigationItem() {
    let resultsController =  UITableViewController(style: .plain)
    navigationItem.searchController = UISearchController(searchResultsController: resultsController)
    navigationItem.hidesSearchBarWhenScrolling = false
    **definesPresentationContext = true**
}