作者:萝莉莲籽芯 | 来源:互联网 | 2022-12-11 18:07
我正在推动一个viewController,我想要一个searchBar,但搜索栏根本没有显示.下面是代码.我错过了什么吗?
var searchCOntroller= UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.placeholder = "Search here..."
definesPresentatiOnContext= true
searchController.searchBar.delegate = self
searchController.searchBar.sizeToFit()
if #available(iOS 11.0, *) {
self.navigationItem.searchCOntroller= searchController
} else {
// Fallback on earlier versions
navigationItem.titleView = searchController.searchBar
navigationItem.titleView?.layoutSubviews()
}
5uper_0leh..
6
您需要将此行添加到代码中:
navigationItem.hidesSearchBarWhenScrolling = false
这样可以在滚动时删除隐藏的searchBar,并在按下视图控制器时显示它。
1> 5uper_0leh..:
您需要将此行添加到代码中:
navigationItem.hidesSearchBarWhenScrolling = false
这样可以在滚动时删除隐藏的searchBar,并在按下视图控制器时显示它。