How to always show the scope of a UISearchBar?

Here is my last issue with the iPhone SDK.

I have a UISearchBar and its delegate is 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 visibility panel as expected. But if you touch the search bar and then outside it (or even perform a search and then cancel it), the visibility panel will be hidden again.

So my question is: is it possible that the visibility bar is always visible? Even after doing a search?

Many thanks.

+7
iphone ios4
source share
1 answer

UISearchDisplayController hides the visibility panel.

The way around this is to subclass UISearchBar and override the setShowsScopeBar implementation:

 @interface MySearchBar : UISearchBar { } @end @implementation MySearchBar - (void) setShowsScopeBar:(BOOL) show { [super setShowsScopeBar: YES]; // always show! } @end 

Then, in the Builder interface, change the class of the search string you are using (associated with UISearchDisplayController) to a new class type - MySearchBar in this example.

+10
source share

All Articles