UISearchDisplayController委托方法不叫
问题描述:
我想添加一个UISearchBar
到我在'nib'文件中定义的表视图。我添加了一个搜索栏和IB搜索显示控制器,链接的搜索栏的出口,并增加这视图控制器的“.H”文件:UISearchDisplayController委托方法不叫
@interface SearchListViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate, UISearchDisplayDelegate>
而且,我已经实现了以下的委托方法:
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText:searchString scope:
[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
return YES;
}
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption
{
[self filterContentForSearchText:self.searchDisplayController.searchBar.text scope:
[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:searchOption]];
return YES;
}
我发现shouldReloadTableForSearchString:
方法被调用,但却shouldReloadTableForSearchScope:
方法不会被调用,所以我的表视图数据不与搜索结果重新加载,有什么能我会丢失?
在此先感谢
答
你必须委托设置为self。
searchController.delegate = self;
searchController.searchResultsDataSource = self;
searchController.searchResultsDelegate = self;
+0
注:由于IOS 8 UISearchDisplayDelegate已被弃用而是使用UISearchDisplayController (如Rajneesh071所述) – MLBDG
只把'UISearchBarDelegate'到.H类不够,你需要设置它像'yourserchbar.delegate =自我;' –