【发布时间】:2018-03-14 04:10:38
【问题描述】:
我已经成功地让 UISearchController 在一个新项目中工作,但是当我尝试在我自己的项目中做同样的事情时,它的行为会有所不同。
这就是我为使其正常工作所做的工作。
故事板:
这是我的视图控制器代码:
class ViewController: UIViewController, UISearchControllerDelegate, UISearchResultsUpdating, UISearchBarDelegate {
var searchController : UISearchController!
override func viewDidLoad() {
super.viewDidLoad()
let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
let modalVC = mainStoryboard.instantiateViewController(withIdentifier: "SearchTableViewController_SBID")
self.searchController = UISearchController(searchResultsController: modalVC)
self.searchController.searchResultsUpdater = self
self.searchController.delegate = self
self.searchController.searchBar.delegate = self
self.searchController.hidesNavigationBarDuringPresentation = false
self.searchController.dimsBackgroundDuringPresentation = true
self.navigationItem.titleView = searchController.searchBar
self.definesPresentationContext = true
}
func updateSearchResults(for searchController: UISearchController) {
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
我得到的结果是,当我点击搜索栏时,背景会变暗,而当我开始输入时,tableview 控制器会可见,会不会搜索栏在导航栏中仍然可见表格视图控制器。
但是,当我尝试在我的项目中实现相同的东西时,当我开始在搜索栏上输入时,表格视图控制器将填满整个屏幕,并且导航栏不可见。
这是我的项目的故事板:
请注意,这两个项目是相似的,除了其中一个是Navigation Controller -> Tab Bar View Controller,当我在搜索栏上键入时它不显示导航栏。
如何在项目Navigation Controller -> Tab Bar View Controller 中显示导航栏?
这是 2 个项目的样子:
【问题讨论】:
标签: ios swift uisearchcontroller uisearchdisplaycontroller