UISearchBarDelegate showsSearchResultsButton属性的正确用法是什么? [英] What is the correct usage of the UISearchBarDelegate showsSearchResultsButton attribute?

查看:637
本文介绍了UISearchBarDelegate showsSearchResultsButton属性的正确用法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将搜索栏配置为显示结果按钮,但该按钮仅在用户输入字符之前显示。此时,X取消按钮取代它。因此,如果不输入字符,搜索结果集将等于整个数据集。我希望结果按钮保持在那里,所以当用户键入足够的字符以获得较小的结果集(如5或6行)时,他们可以单击结果按钮,我的代表将被调用,我可以显示结果集。

I configure my search bar to show the results button, but the button only shows until the user enters a character. At that point, the "X" cancel button replaces it. So without entering characters, the search result set equals the entire data set. I'd like the results button to stay there so when the user has typed enough characters to get a smaller result set (like 5 or 6 rows), they can click the results button, my delegate will get called, and I can show just that result set.

UISearchBar * theSearchBar = [[UISearchBar alloc] 
                             initWithFrame:CGRectMake(0,0,700,40)];
theSearchBar.delegate = self;

theSearchBar.placeholder = @"What are you looking for?";
theSearchBar.showsCancelButton = NO;         // shows up after first char typed.
theSearchBar.showsSearchResultsButton = YES; // disappears just when I need it.

...在VC中进一步向下...此方法只能在搜索栏的输入时调用字段为空。

...further down in the VC... this method can only called when the search bar's input field is empty.

 - (void)searchBarResultsListButtonClicked:(UISearchBar *)searchBar {
         NSLog(@" searchBarResultsListButtonClicked for %@",searchBar); // 
    }

建议,教程,示例代码和合理的dope-slaps欢迎。
TIA
-Mike

Advice, tutorials, sample code and justified dope-slaps welcome. TIA -Mike

推荐答案

@Rayfleck,我认为你不应该担心搜索结果按钮所有。

@Rayfleck, I think you should not worry about Search Results Button at all.

如果您需要监控用户的输入,直到输入足够的字符进行过滤:

If what you need is to monitor user's input until they have entered enough characters for filtering:

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
    if ([searchText length]>5) {
        [self filterDataWithKeyword:searchText];
        [self.tableView reloadData];
    } else {
        [self resetFilter];
        [self.tableView reloadData];
    }
}

这篇关于UISearchBarDelegate showsSearchResultsButton属性的正确用法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆