如何在 UISearchBar 中设置范围

发布于 2024-09-14 08:44:11 字数 80 浏览 2 评论 0原文

我有一个工作正常的 UISearchBar,但我想知道如何根据某些条件设置范围和过滤结果,例如:“狗和“猫”

教程和示例代码欢迎。

I have a UISearchBar which is working fine, but I was wondering how I can set a scope and filter results based on certain criteria like: "Dogs and "Cats"

Tutorials and example code welcome.

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

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

发布评论

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

评论(1

云柯 2024-09-21 08:44:11

如果您使用 Interface Builder,只需添加范围按钮标题。要以编程方式添加它们,请参阅此答案

范围按钮从 0 开始索引。

实现 UISearchDisplayDelegateUISearchBarDelegate。您必须实现下面的方法(以及其他 2 个方法)

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption

在上面的方法中使用 searchOption 来获取用户选择的范围索引。
如果您的条件必须采用字符串形式,那么您应该找到一种将字符串映射到整数值的方法,例如使用 NSDictionary 或手动比较 if (0 == searchOption) .. .

If you use Interface Builder just add the scope button titles. To add them programmatically, see this answer.

The scope buttons are indexed from 0.

Implement UISearchDisplayDelegate and UISearchBarDelegate. You will have to implement the method below (along with 2 others)

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption

Inside the method above use searchOption to get the scope index the user has selected.
If your criteria has to be in string form then you should find a way to map the string to an integer value e.g use the NSDictionary or just manually compare if (0 == searchOption) ...

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