如何知道哪个搜索栏处于活动状态?

发布于 2024-11-24 04:12:51 字数 192 浏览 3 评论 0原文

现在我在一页上有 2 个搜索栏,

第一个问题是如何使搜索按钮始终显示,尽管 searchbar.text 上没有文本?

第二个问题是,我有一个表视图,它将显示不同的列表,消耗我选择的搜索栏,我怎样才能做得好?

我可以设置一个变量,该变量每次搜索栏处于活动状态时都会发生变化。但是,有没有办法查看哪个搜索栏当前是活动搜索栏?

now I have 2 search bar at one page

the first problem is How can I make a search button always show although no text at searchbar.text?

the second problem is, I have a Table View that Will show a different list expend which search bar I choose, how can I do it well?

I can set a variable that change everytime the search bar is active. However is there a way to see which search bar is currently the active search bar?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苦行僧 2024-12-01 04:12:51

检查您正在使用哪个视图的最简单方法是分配 tag 属性:

firstSearchBar.tag = 100;
secondSearchBar.tag = 200;

您可以轻松检查它:

if(searhBar.tag == 100) {
    // it is first search bar
} else if(searchBar.tag == 200) {
    // it is second search bar
}

现在是第二部分。如果你想显示取消按钮,你可以这样做:

searchBar.showsCancelButton = YES;

如果你想显示范围栏:

searchBar.showsScopeBar = YES;

如果你想显示搜索结果按钮:

searchBar.showsSearchResultsButton = YES;

编辑: 如果你想显示 搜索键盘按钮即使没有输入任何文本,您也可以这样做:

UITextField *searchField = (UItextField *)[[searchBar subviews] objectAtIndex:0];
[searchField.enablesReturnKeyAutomatically = NO;

我建议您阅读UISearchBar 的文档

The simplest way to check which view are you working with, is assigning the tag property:

firstSearchBar.tag = 100;
secondSearchBar.tag = 200;

You can easily check it:

if(searhBar.tag == 100) {
    // it is first search bar
} else if(searchBar.tag == 200) {
    // it is second search bar
}

Now, the second part. If you want to show cancel button, you can do it in this way:

searchBar.showsCancelButton = YES;

If you want to show scope bar:

searchBar.showsScopeBar = YES;

If you want to show search results button:

searchBar.showsSearchResultsButton = YES;

EDIT: If you wish to show Search keyboard button even if there's no text entered, you can do it in this way:

UITextField *searchField = (UItextField *)[[searchBar subviews] objectAtIndex:0];
[searchField.enablesReturnKeyAutomatically = NO;

I recommend you reading UISearchBar's documentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文