Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have UISearchBar scope bar always visible?

Tags:

iphone

ios4

Here's my latest problem with the iPhone SDK.

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?

Thanks a lot.

like image 590
Aloha Silver Avatar asked Aug 09 '10 23:08

Aloha Silver


1 Answers

The UISearchDisplayController is hiding the scope bar for you.

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

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.

like image 139
TomSwift Avatar answered Sep 19 '22 19:09

TomSwift