即使按下取消按钮后如何保留范围栏?
我有一个 UITableView,顶部有一个搜索栏。我使用 UISearchDisplayController 来实现相同的功能。它还有一个带有两个按钮的范围栏。默认情况下,当我启动应用程序时,将显示范围栏。当我在搜索后单击取消按钮时,范围栏消失了。那么,即使在我按下“取消”按钮后,有什么方法可以保留范围栏吗?我使用了以下代码,但它不起作用。
- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar
{
[searchBar setShowsScopeBar:YES];
return YES;
}
谢谢 :)
I have a UITableView with a searchbar on the top. I used UISearchDisplayController for implementing the same. And also it has a scope bar with two buttons. In default when I launch the app, the scope bar will be displayed. When I click the cancel button after the searching, the scopebar disappeared. So is there any way to keep the scopebar even after I pressed the Cancel button. I used the following code but its not working.
- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar
{
[searchBar setShowsScopeBar:YES];
return YES;
}
Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我今天遇到了这个问题,我想我已经找到了解决方案。
您需要做两件事:
最终代码:
I've had the problem today and I think I've found a solution.
You need to do two things:
Final code:
在过去的几天里,我自己也一直在与这类
UISearchBarController
问题作斗争,我不得不说,使用 UISearchBar 做任何不寻常的事情的最佳方法就是不使用UISearchDisplayController
代码>根本!只需使用
UISearchBar
和UISearchBarDelegate
方法并推出您自己的方法,然后您就可以将所有内容设置为完全按照您想要的方式运行。这是我在最近的一个项目中所做的。
- 范围栏始终保持可见
- 输入文本后我立即进行过滤
- 如果范围发生变化,我会立即过滤
- 当不需要时我隐藏取消按钮
- 不需要时我会隐藏键盘,
效果很好:)
I have also been battling with these kinds of
UISearchBarController
problems the last few days myself, and I have to say the best way to do anything unusual with a UISearchBar is to not use aUISearchDisplayController
at all!Just use a
UISearchBar
and theUISearchBarDelegate
methods and roll your own, then you can set everything all up to act exactly how you want.Here what I did in one recent project.
- The scope bar always stays visible
- I filter immediately as text is entered
- I filter immediately if scope is changes
- I hide the cancel button when it's not needed
- I hide the keyboard when it's not needed
Works great :)
这个答案更正确的方法是添加返回结果的逻辑:
More correct way of this answer is to add logic for return result: