Search code examples
iosobjective-cipaduisearchbaruisearchcontroller

Positioning of scope bar in UISearchController


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


Solution

  • 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