Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scopeBar don't show under UISearchBar when it is active for the first time

I programmatically created a UISearchController, and set the scope button titles in viewDidLoad

UITableViewController *searchResultsController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
searchResultsController.tableView.dataSource = self;
searchResultsController.tableView.delegate = self;
[searchResultsController.tableView registerNib:musicNib forCellReuseIdentifier:@"MusicCell"];

self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];
self.searchController.searchResultsUpdater = self;
UISearchBar *searchBar = self.searchController.searchBar;
searchBar.scopeButtonTitles = @[@"Album", @"Artist", @"Song"];
searchBar.showsScopeBar = YES;
searchBar.selectedScopeButtonIndex = 0;
searchBar.delegate = self;

self.tableView.tableHeaderView = self.searchController.searchBar;

But when I search in search bar when view loaded. the scope bar don't show up. The second I search in search bar, the scope bar shows. What's going on?

first time search, scope bar don't showsecond time search, scope bar shows

like image 990
yong ho Avatar asked Nov 26 '22 07:11

yong ho


1 Answers

Try this:

searchBarDisplayController.searchBar.showsScopeBar = NO;
searchBarDisplayController.searchBar.scopeButtonTitles = nil;

Based on your comment, put the above code in searchDisplayControllerWillBeginSearch: delegate method. That should work.

like image 104
Faig Huseynov Avatar answered Dec 24 '22 18:12

Faig Huseynov