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

UISearchBar not showing on device but is showing in simulator

我有一个 table 视图,我通过将以下内容放入我的 table 视图 class 中添加了一个搜索控制器,我确保添加 [=12] =] 在 class 定义中。

let 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