【发布时间】:2016-11-28 14:42:08
【问题描述】:
我不知道为什么会这样。我有一个带有 UITableView 的 UIViewController,我想在其中添加一个搜索栏,以使用新的 UISearchController(Swift 3,Xcode 8.1)查询我的服务器。 我已经尝试了所有方法,例如在界面生成器中添加搜索栏,将搜索栏背景设置为 UIImage,但没有任何效果。
这是视图控制器的类准系统:
class MyViewController: UIViewController {
var searchController = UISearchController(searchResultsController: nil)
fileprivate func setupSearchController() {
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.barTintColor = .myColor()
searchController.searchBar.tintColor = .white
searchController.searchBar.backgroundColor = .myColor()
searchController.searchBar.placeholder = "searchSomething"
searchController.searchBar.delegate = self
definesPresentationContext = true
tableView.tableHeaderView = searchController.searchBar
}
}
extension MyViewController: UISearchResultsUpdating, UISearchBarDelegate {
// delegates methods...
}
也许这与我的设计模式有关,但我不确定 UISearchController 是否真的很新,而且我在网络上没有找到任何关于其使用的好例子。
【问题讨论】:
标签: swift3 uisearchbar xcode8 uisearchdisplaycontroller uisearchcontroller