I have a UISearchBar and its respective Search Display Controller laid out in xib file via InterfaceBuilder. The search bar is configured in Interface Builder with "Shows Scope Bar" unchecked. However, once text entry starts in the search bar and the 'search overlay' is shown, UISearchBar is shown with the Scope Bar that has 2 buttons and their default "Title".
How do I make sure that the Scope Bar is not shown when SearchBar editing has begun?
I've tried these from my ViewController class that manages the search bar:
- (void)viewDidLoad
{
UISearchBar *searchBar = self.searchDisplayController.searchBar;
NSLog(@"Scopebar is visible? %@", searchBar.showsScopeBar == YES ? @"YES" : @"NO");
searchBar.showsScopeBar = NO; // Doesn't seem to have an effect
}
#pragma mark - UISearchBarDelegate methods
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
[searchBar setShowsScopeBar:NO]; // doesn't seem to work either
return YES;
}
Apple's sample code, TableSearch, that illustrates search has the 4 button scope bar once search has started.
If you look in InterfaceBuilder you will see "Title" twice in the "Scope Titles" list just underneath the "Shows Scope Bar" checkbox. InterfaceBuilder adds them when you check the checkbox. It doesn't remove them when you uncheck, but they will still appear when you click in the Search box in your running app. In InterfaceBuilder, temporarily re-enable the "Shows Scope Bar" checkbox to allow you to select each "Title" row and click the "-" button to remove them. Then un-check "Shows Scope Bar". You shouldn't see them any more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With