I know this question was asked several times before, and it was solved(Before I was using that solution with iOS4 and 5). My recent project involves using UISearchBar
with some other views, and I want to show it's scope buttons when it becomes active. Before, in UISearchBardelegate
's - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
I was doing
[searchBar setShowsScopeBar:YES];
[searchBar sizeToFit];
and it was showing scope buttons. But now, on iOS6 this code does nothing. UISearchBar
is added in IB, it's delegate is set to my view controller.
Anybody has solution for this problem? Thanks in advance.
I reported this as a bug to Apple and got an answer how to fix it:
Just subclass UISearchBar and override -setShowsScopeBar:
UPDATE: This is fixed in iOS 7.
It looks like what's going on is that the
UISearchBar
is failing to invalidate its intrinsic content size when it shows and hides the scope bar.Until it's fixed in UIKit, it's extremely easy to work around it by simply subclassing
UISearchBar
and overriding a single method:Ok, problem was with iOS 6 auto layout thing, once I'va removed it, problem was gone. Thanks everyone :)
Another way to do this in iOS 6.0 without having to subclass UISearchBar is just by adjusting the frame size in the Search Bar Delegate: