简体   繁体   English

如何在UISearchBar中选择范围?

[英]How can I multi select scope in UISearchBar?

I am working on an iPhone application that has a UISearchBar which populates a table view. 我正在使用一个具有填充表格视图的UISearchBar的iPhone应用程序。 I have various options on my search that could be easily hooked into the 'scope' functionality. 我在搜索中有多种选择,可以轻松地加入“作用域”功能。 However, I really need to have two groups of buttons. 但是,我确实需要两组按钮。 One group would be 'scope' determining the type of search, and one group that indicates the sort order of the results returned. 一组是确定范围的搜索类型,另一组是指示返回结果的排序顺序。 As far as I can tell, you can only have one 'scope' item selected at once, using the normal functionality. 据我所知,使用正常功能一次只能选择一个“范围”项。

I only load a small portion of the possibly results with each query (for speed), so I can't sort using the table view alone. 我每次查询都只加载一小部分可能的结果(以提高速度),所以我不能仅使用表视图进行排序。 It needs to be passed to my search query each time, thus I need the user to be able to choose both a search type and a search order. 每次都需要将其传递给我的搜索查询,因此我需要用户能够选择搜索类型和搜索顺序。

Right now, I just have two different UISegmentedControl's below my UISearchBar, and I do everything by hand. 现在,我在UISearchBar下面只有两个不同的UISegmentedControl,并且我手工完成所有操作。 This works. 这可行。 However, even if I make the background grayish, it doesn't have the look of being part of the search bar (like the scope on the mail.app). 但是,即使我将背景设为灰色,也不会看起来像是搜索栏的一部分(例如mail.app上的范围)。

Any ideas? 有任何想法吗? I am fairly new at the SDK, so it is very possible I missed something. 我在SDK上还很新,所以很可能错过了一些东西。 I only found out about the scope functionality after I had already coded the segmented controls by hand! 我只有在手动编码分段控件后才了解范围功能!

I'm not sure if this will help but you can access the segmented control that is used with the search bar with the code below. 我不确定这是否有帮助,但是您可以使用以下代码访问与搜索栏一起使用的分段控件。 Maybe you can tweak or replace it with something? 也许您可以调整或替换为其他内容?

// Find scope segmented control
for (UIView *v in searchBar.subviews) {
    if ([v isMemberOfClass:[UISegmentedControl class]]) {   

        // You've got the segmented control!        
        UISegmentedControl *scope = (UISegmentedControl *)v;

        // Do your thing here...

    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM