我在情节提要中有tableViewController。 我以编程方式将searchController添加到表头。
private func setupSearchView(){
if !showSearchBar { return }
let storyboard = uistoryboard(name: "Search",bundle: nil)
resultViewController =
storyboard.instantiateViewController(withIdentifier: "NewSearchTableViewController") as? SearchResultTableViewController
searchController = UISearchController(searchResultsController: resultViewController)
resultViewController?.tableView.delegate = self
searchController.delegate = self
searchController.searchResultsUpdater = self
searchController.searchBar.delegate = self // Monitor when the search button is tapped.
searchController.hidesnavigationBarDuringPresentation = false
searchController.dimsBackgroundDuringPresentation = false
tableView.tableHeaderView = searchController.searchBar
searchController.searchBar.sizeToFit()
searchController.searchBar.placeholder = "Search here...".localized
definesPresentationContext = true
}
当我在表格中选择单元格并转到详细信息屏幕时,它可以完美运行。 但是当我向后按下按钮时,搜索栏在导航栏下方滚动。