Search code examples
iosuisearchbaruisearchcontroller

iOS - Keep ScopeBar even after Cancel Button click


I set the setShowsScopeBar to TRUE from the very beginning, and that works perfectly. But once I search something and then cancel my search, the Scope Bar disappears.

How to keep scopebar even after pressed Cancel button?

Apparently, in earlier version, with the UISearchBar,

    - (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar
{
    [searchBar setShowsScopeBar:YES];
    return YES;
}

This worked. But with the SearchController, it isn't the case anymore.

I have tried this:

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
    searchController.searchBar.showsScopeBar = YES;
    [searchController.searchBar sizeToFit];
    isSearching = NO;
}

with no luck.

Are there any possible solutions out there on iOS 9?


Solution

  • There is no direct way of keeping the scope bar always visible unless you use some hacks.

    Instead use a UISegmentedControl which looks like a scope bar. Then handle the filtering of the search results in - updateSearchResultsForSearchController: based on the selected segment.