我有一个 TableView ,通过将以下内容添加到我的 TableView 类中,我已在其中添加了搜索 Controller ,并确保在类定义中添加 UISearchBarDelegate
。
让 searchDisplay = UISearchController(searchResultsController: nil)
然后在我的 viewDidLoad 函数中输入:
searchDisplay.searchResultsUpdater = self
searchDisplay.dimsBackgroundDuringPresentation = false
definesPresentationContext = true
tableView.tableHeaderView = searchDisplay.searchBar
然后,我有一些函数可以根据搜索的内容获取所需的数据。
还在类(class)之后但在同一个文件中添加了此内容:
extension AllTableViewController: UISearchResultsUpdating{
func updateSearchResultsForSearchController(searchDisplay: UISearchController) {
filterContentForSearchText(searchDisplay.searchBar.text!)
}
}
正如我在标题中所说,所有代码似乎都在模拟器中顺利运行,但是当我在设备上运行它时,搜索栏就不会出现。输出框中没有出现不同的消息,所以我真的不知道从哪里开始。
最佳答案
您是否尝试过在搜索栏上调用 sizeToFit ? – keithbhunter 6 月 30 日 13:43
关于ios - UISearchBar 未显示在设备上,但显示在模拟器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38124089/