4

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?

Community
  • 1
  • 1
el-flor
  • 1,466
  • 3
  • 18
  • 39

2 Answers2

0

The element is a UISegmentedControl with the UISegmentedControlStyleBar style. You can set the tintColor property to get the color desired. Just put the view above the table view and you can get something that looks like that screenshot.

Andy Darwin
  • 478
  • 5
  • 19
0

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.

Praveen Gowda I V
  • 9,569
  • 4
  • 41
  • 49
  • Does anyone know if this is still the case, or is there now a way to keep the scope bar visible in iOS 11/Swift 4? – Eli Whittle Jun 08 '18 at 05:22