UISearchDisplayController
(UISearchDisplayDelegate
也已弃用。)所以现在我无法使用下一个委托方法:
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller
shouldReloadTableForSearchScope:(NSInteger)searchOption
我只能使用UISearchResultsUpdating
委托方法:
- (void)updateSearchResultsForSearchController:(UISearchController *)searchController
我的问题是,如果我只引用UISearchController
,我如何知道searchScore何时更改以及现在选择了哪个项目。我一直在找一个合适的房产,但没找到。感谢。
答案 0 :(得分:0)
使用UISearchBarDelegate
首先,确保您的View Controller实现UISearchBarDelegate协议,如:
class ViewController: UITableViewController, UISearchResultsUpdating, UISearchBarDelegate {
//code
}
设置委托:
controller.searchBar.delegate = self
然后实现以下方法:
func searchBar(searchBar: UISearchBar, selectedScopeButtonIndexDidChange selectedScope: Int) {
let scopeTitles = searchBar.scopeButtonTitles as [String]
let scope = scopeTitles[selectedScope]
println(scope)
}