我正在以编程方式进行。我也尝试将它设置到 TitleView 中,但它不起作用。 代码如下:
//searchBar
let searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.placeholder = "Search Players"
navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = false
definesPresentationContext = true
我在 searchBar 下也有一个 ScopeBar,选中时。 如果我这样做:
searchController.titleView = searchController.searchBar
它就位了,但我不能再选择/点击搜索栏了。
最佳答案
对我来说,您的示例运行良好,但也许您可以使用它。
navigationItem.titleView = searchController.searchBar
您可以像这里一样将搜索栏插入导航中。 你能解释一下 TableView 标题中的搜索栏有什么问题吗?什么不工作?
关于ios - searchBar 未在 navigationItem 中居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52388312/