我正在尝试将 UISearchBar 添加到我在“nib”文件中定义的表格 View 中。我在 IB 中添加了一个搜索栏和搜索显示 Controller ,链接了搜索栏 socket ,并将其添加到 View Controller 的 '.h' 文件中:
@interface SearchListViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate, UISearchDisplayDelegate>
另外,我实现了以下委托(delegate)方法:
- (BOOL)searchDisplayControllerUISearchDisplayController *)controller shouldReloadTableForSearchStringNSString *)searchString
{
[self filterContentForSearchText:searchString scope:
[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
return YES;
}
- (BOOL)searchDisplayControllerUISearchDisplayController *)controller shouldReloadTableForSearchScopeNSInteger)searchOption
{
[self filterContentForSearchText:self.searchDisplayController.searchBar.text scope:
[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:searchOption]];
return YES;
}
我发现 shouldReloadTableForSearchString: 方法被调用,但是 shouldReloadTableForSearchScope: 方法从未被调用,所以我的表格 View 数据没有重新加载搜索结果......什么我会失踪吗?
提前致谢
Best Answer-推荐答案 strong>
您必须将委托(delegate)设置为自己。
searchController.delegate = self;
searchController.searchResultsDataSource = self;
searchController.searchResultsDelegate = self;
UISearchDisplayController Class Reference
关于ios - 未调用 UISearchDisplayController 委托(delegate)方法,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/19486536/
|