2

我正在尝试将一个添加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:从未调用过方法,因此我的表格视图数据没有重新加载搜索结果......我会丢失什么?

提前致谢

4

1 回答 1

4

您必须将委托设置为自我。

searchController.delegate = self;
searchController.searchResultsDataSource = self;
searchController.searchResultsDelegate = self;

UISearchDisplayController 类参考

于 2013-10-22T05:32:39.940 回答