Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turning off the scope bar in UISearchBar once editing has begun

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.

like image 384
Stephan Keene Avatar asked Nov 27 '22 22:11

Stephan Keene


1 Answers

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.

like image 64
Geoff Hackworth Avatar answered Dec 06 '22 00:12

Geoff Hackworth