1

I'm developing a iPad-only app, and I've got a UITableView inside a UIViewController. I setted a UISearchController as the header of the UITableView. This search control has three scopes. I want the scope selector to be below the search bar. With the following piece of code, I'm able to get it at init, but when I start with the input, the selector goes to the right, and remains there.

Here is an animation:

F***ing scope selector

And here is the relevant code:

self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;    

self.searchController.searchBar.scopeButtonTitles = @[@"Uno",@"Dos", @"Tres"];
self.searchController.searchBar.delegate = self;
self.tableView.tableHeaderView = self.searchController.searchBar;
self.searchController.searchBar.showsScopeBar = YES;
self.definesPresentationContext = YES;

[self.searchController.searchBar sizeToFit];

Thanks in advance

webo80
  • 3,365
  • 5
  • 35
  • 52

2 Answers2

1

I've also incorporated a UISearchController inside my app. I'm using Xcode 7.1.

I had the same problem and simply removed "self.searchController.searchBar.showsScopeBar" from my code.

Either change the value to false or remove it completely.

self.searchController.searchBar.showsScopeBar = false

Lance Samaria
  • 17,576
  • 18
  • 108
  • 256
1

Here's something interesting I read from apple:

When a search bar is present, a scope bar can appear near it. The scope bar displays below the search bar, regardless of orientation, unless you use a search display controller in your code (for more information on the way this works, see UISearchDisplayController Class Reference). When you use a search display controller, the scope bar is displayed within the search bar to the right of the search field when the device is in landscape orientation (in portrait orientation, it’s below the search bar).

So what worked for me was using only a UISearchBar instead of the whole UISearchDisplayController.

andrei
  • 1,353
  • 15
  • 24