gpt4 book ai didi

ios - 未调用 UISearchDisplayController 委托(delegate)方法

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:45:05 24 4
gpt4 key购买 nike

我正在尝试将 UISearchBar 添加到我在“nib”文件中定义的表格 View 中。我在 IB 中添加了搜索栏和搜索显示 Controller ,链接了搜索栏 socket ,并将其添加到 View Controller 的“.h”文件中:

@interface SearchListViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate, UISearchDisplayDelegate>

此外,我还实现了以下委托(delegate)方法:

- (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: 方法从未被调用,所以我的 TableView 数据没有重新加载搜索结果......什么我会失踪吗?

提前致谢

最佳答案

您必须将委托(delegate)设置为自己。

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

UISearchDisplayController Class Reference

关于ios - 未调用 UISearchDisplayController 委托(delegate)方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19486536/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com