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