如何让UISearchBar范围栏始终可见? [英] How to have UISearchBar scope bar always visible?
问题描述
这是我在iPhone SDK上遇到的最新问题。
Here's my latest problem with the iPhone SDK.
我有一个UISearchBar及其代表全部设置完毕。
另外,当我加载我的视图时,我调用
I've got a UISearchBar and its delegate all set up. Also, when I load my view, I call
self.searchDisplayController.searchBar.showsScopeBar = YES;
这样,当我的视图首次出现时,我会看到范围栏,如预期的那样。
但是如果触摸搜索栏内部然后在其外部(或者即使执行搜索然后取消它),范围栏也会再次隐藏。
That way, when my view is first presented, I see the scope bar, as expected. But if touch inside the search bar and then outside it (or even if a perform a search and then cancel it), the scope bar gets hidden again.
所以我的问题是:是否可以让范围栏始终可见?甚至在进行搜索后?
So my question is: is it possible to have the scope bar always visible? Even after performing searches?
非常感谢。
推荐答案
UISearchDisplayController正在为你隐藏范围栏。
The UISearchDisplayController is hiding the scope bar for you.
解决这个问题的方法是继承UISearchBar并覆盖setShowsScopeBar的实现:
The way around this is to subclass UISearchBar and override the implementation of setShowsScopeBar:
@interface MySearchBar : UISearchBar {
}
@end
@implementation MySearchBar
- (void) setShowsScopeBar:(BOOL) show
{
[super setShowsScopeBar: YES]; // always show!
}
@end
然后,在Interface Builder中,将视图中的搜索栏(与UISearchDisplayController相关联)的类更改为新类类型 - 在此示例中为MySearchBar。
Then, in Interface Builder, change the class of the Search Bar you have in your view (that is associated with the UISearchDisplayController) to the new class type -- MySearchBar in this example.
这篇关于如何让UISearchBar范围栏始终可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!