我有一个完美的SearchController
,目前位于tableView
的顶部
tableView.tableHeaderView = searchController.searchBar
但是我想让searchBar
始终保持在tableView
之上,即使在滚动时也是如此。我通过故事板添加了它,但它显示但是它没有正常工作,当我在mySearch
输入时,结果没有更新
我的代码:
@IBOutlet weak var mySearch: UISearchBar!
func configureSearchController(){
searchController = UISearchController(searchResultsController: nil)
definesPresentationContext = true
searchController.definesPresentationContext = true
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.placeholder = "Search for songs"
searchController.searchBar.delegate = self
searchController.searchBar.sizeToFit()
searchController.searchBar.tintColor = GlobalSettings.tint.color
searchController.searchBar.contentMode = .scaleAspectFill
searchController.hidesNavigationBarDuringPresentation = false;
searchController.searchBar.searchBarStyle = .minimal
mySearch = searchController.searchBar
}
如何正确连接@IBOutlet searchBar
到searchController
?
答案 0 :(得分:0)
您是否尝试过将插座从UISearchBar
更改为UISearchController
?
如果我没弄错的话,它确实可以在故事板中使用UISearchBar。
这是更新的代码:
@IBOutlet weak var mySearch: UISearchController!
func configureSearchController(){
definesPresentationContext = true
searchController.definesPresentationContext = true
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.placeholder = "Search for songs"
searchController.searchBar.delegate = self
searchController.searchBar.sizeToFit()
searchController.searchBar.tintColor = GlobalSettings.tint.color
searchController.searchBar.contentMode = .scaleAspectFill
searchController.hidesNavigationBarDuringPresentation = false;
searchController.searchBar.searchBarStyle = .minimal
}