简体   繁体   English

UISearchBar未显示在设备上,但显示在模拟器中

[英]UISearchBar not showing on device but is showing in simulator

I have a table view that I have added a search controller in to by putting the following in to my table views class which I made sure to add UISearchBarDelegate in the class definition. 我有一个表视图,已通过将以下内容添加到表视图类中来添加了搜索控制器,该类确保确保在类定义中添加UISearchBarDelegate

let searchDisplay = UISearchController(searchResultsController: nil)

Then in my viewDidLoad function I entered this: 然后在我的viewDidLoad函数中输入以下内容:

searchDisplay.searchResultsUpdater = self
searchDisplay.dimsBackgroundDuringPresentation = false
definesPresentationContext = true
tableView.tableHeaderView = searchDisplay.searchBar

I then have functions that get the required data depending on what has been searched. 然后,我有一些函数可以根据搜索到的内容获取所需的数据。

Also added this after the class but in the same file: 还在类之后但在同一文件中添加了此内容:

extension AllTableViewController: UISearchResultsUpdating{
    func updateSearchResultsForSearchController(searchDisplay: UISearchController) {
        filterContentForSearchText(searchDisplay.searchBar.text!)
    }
}

As I say in the title the code all seems to run swimmingly in the Simulator but when I run it on a device the search bar just doesn't appear. 正如我在标题中所说的那样,所有代码似乎都在Simulator中流畅地运行,但是当我在设备上运行它时,搜索栏就不会出现。 No different messages appear in the output box so I don't really know where to start. 输出框中没有其他消息,所以我真的不知道从哪里开始。

Have you tried a sizeToFit call on the search bar? 您是否在搜索栏上尝试过sizeToFit呼叫? – keithbhunter Jun 30 at 13:43 – keithbhunter 6月30日13:43

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM