当我将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
}
}
答案 0 :(得分:2)
找到答案:
definesPresentationContext = true
如:
private func configureNavigationItem() {
let resultsController = UITableViewController(style: .plain)
navigationItem.searchController = UISearchController(searchResultsController: resultsController)
navigationItem.hidesSearchBarWhenScrolling = false
**definesPresentationContext = true**
}