【发布时间】:2013-10-29 11:22:21
【问题描述】:
我正在尝试将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: 方法从未被调用,所以我的表格视图数据没有重新加载搜索结果......我会丢失什么?
提前致谢
【问题讨论】:
-
仅将
UISearchBarDelegate放入 .h 类还不够,您需要将其设置为yourserchbar.delegate=self;
标签: ios uitableview uisearchbar uisearchdisplaycontroller uisearchbardelegate