我尝试在UIViewcontroller中显示searchController。 这工作正常,但是当我尝试写东西时,搜索控制器不可见。
我的代码如下:
class tempVC: UIViewController,UISearchBarDelegate,UISearchResultsUpdating {
let searchController = UISearchController(searchResultsController: nil)
override func viewDidLoad() {
super.viewDidLoad()
searchController.searchResultsUpdater = self
searchController.searchBar.delegate = self
searchController.searchBar.placeholder = "Enter name here..."
definesPresentationContext = true
searchController.searchBar.sizeToFit()
searchController.dimsBackgroundDuringPresentation = false
searchController.hidesNavigationBarDuringPresentation=false
//navigationItem.titleView = searchController.searchBar
searchController.searchBar.frame=CGRectMake(0, 64, 320, 44)
self.view.addSubview(searchController.searchBar)
}
// MARK: - UISearchResultsUpdating Delegate
func updateSearchResultsForSearchController(searchController: UISearchController) {
// let searchBar = searchController.searchBar
//let scope = searchBar.scopeButtonTitles![searchBar.selectedScopeButtonIndex]
//filterContentForSearchText(searchController.searchBar.text!, scope: scope)
print("update")
}
}
请帮我解决此问题。
谢谢,
答案 0 :(得分:0)
class tempVC:UIViewController,UISearchBarDelegate,UISearchResultsUpdating {
let searchController = UISearchController(searchResultsController: nil)
override func viewDidLoad() {
super.viewDidLoad()
searchController.searchResultsUpdater = self
searchController.searchBar.delegate = self
searchController.searchBar.placeholder = "Enter name here..."
definesPresentationContext = true
searchController.searchBar.sizeToFit()
searchController.dimsBackgroundDuringPresentation = false
searchController.hidesNavigationBarDuringPresentation=false
//navigationItem.titleView = searchController.searchBar
searchController.searchBar.frame=CGRectMake(0, 64, 320, 44)
self.view.addSubview(searchController.searchBar)
}
// MARK: - UISearchResultsUpdating Delegate
func updateSearchResultsForSearchController(searchController: UISearchController) {
// let searchBar = searchController.searchBar
//let scope = searchBar.scopeButtonTitles![searchBar.selectedScopeButtonIndex]
//filterContentForSearchText(searchController.searchBar.text!, scope: scope)
print("update")
}
}