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

标签 ios swift uisearchcontroller

我有一个 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/

相关文章:

ios - 单击 UITabBarController 时的自定义操作

ios - 如何在 Objective C 中编写以下代码?

ios11 - 顶部安全区域约束动画

swift - iOS 11 中的 UISearchBar 对齐问题

ios - APNS - 将应用程序从生产中转移到开发中

位置权限的 iOS alertview 不会弹出

iphone - iphone 相机拍照前如何设置延迟?

swift - 如何更改整个应用程序的 UITableView 的颜色?

ios - Swift:没有实例变量的对象的 NSCoding 实现

swift - UISearchController searchBar 不更新 barTintColor