我正在将actionController添加到navigationItem中。在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
}
}
在调试导航器中,
在尺寸检查器中,