【发布时间】:2019-10-01 05:55:29
【问题描述】:
我在 navigationItem 中添加了 searchController 。在 iOS12 中,它可以正常显示,但在 iOS 13 中它没有显示。在调试视图层次结构时,它显示已添加搜索栏,但其高度已设置为零。无法追踪正确的解决方案。
代码:
func setupSearchController() {
searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self as UISearchResultsUpdating
searchController.searchBar.placeholder = "Search here..."
searchController.searchBar.delegate = self as UISearchBarDelegate
searchController.searchBar.tintColor = .white
searchController.searchBar.barTintColor = .white
searchController.hidesNavigationBarDuringPresentation = false
searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.showsCancelButton = true
if let textfield = searchController.searchBar.value(forKey: "searchField") as? UITextField {
textfield.textColor = UIColor.blue
if let backgroundview = textfield.subviews.first {
// Background color
backgroundview.backgroundColor = UIColor.white
// Rounded corner
backgroundview.layer.cornerRadius = 10;
backgroundview.clipsToBounds = true;
}
}
if #available(iOS 11.0, *) {
self.navigationItem.searchController = searchController
} else {
self.tblView.tableHeaderView = searchController.searchBar
}
}
在调试导航器中,
在尺寸检查器中,
【问题讨论】:
-
如果您删除所有弄乱搜索字段文本字段的hacky代码怎么办?
-
@matt 还是和上面一样
-
它的答案和我在这里写的代码一样,但在这里还是不行。
标签: ios swift uisearchcontroller ios13