我正在尝试将UISearchBar
添加到我在'nib'文件中定义的表视图中。我在IB中添加了一个搜索栏和搜索显示控制器,链接了搜索栏插座,并将其添加到视图控制器的'.h'文件中:
@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:
方法,因此我的表格视图数据不会重新加载搜索结果...我可能会丢失什么?
提前致谢
答案 0 :(得分:4)
您必须将委托设置为自己。
searchController.delegate = self;
searchController.searchResultsDataSource = self;
searchController.searchResultsDelegate = self;