UISearchBar visibility bar not showing in iOS 7?

I am creating a UISearchViewController and I want to put a UISearchBar in the navigation element of the navigation controller. Here is how I did it without any results:

 self.searchBar = [UISearchBar new]; self.searchBar.showsScopeBar = YES; self.searchBar.scopeButtonTitles = @[@"Users", @"Hashtags"]; self.searchBar.delegate = self; self.searchController = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar contentsController:self]; self.searchController.delegate = self; self.searchController.searchResultsDataSource = self; self.searchController.searchResultsDelegate = self; self.searchController.displaysSearchBarInNavigationBar = YES; 

I also tried:

 self.searchDisplayController.searchBar.searchBarStyle = UISearchBarStyleMinimal; self.searchDisplayController.searchBar.scopeButtonTitles = @[@"Users", @"Hashtags"]; self.searchDisplayController.searchBar.showsScopeBar = YES; 

Did I miss something or did something wrong?

Edit: This and this is exactly what I'm aiming for.

+6
source share
4 answers

Try the following code

 UISearchBar* searchBar = [[UISearchBar alloc] initWithFrame:CGRectZero]; searchBar.barStyle = UIBarStyleBlack; searchBar.scopeButtonTitles = [NSArray arrayWithObjects:@"Users", @"Hashtags", nil]; searchBar.showsScopeBar = YES; self.searchBar.delegate = self; 
+1
source

The visibility bar will only appear if the search bar is active. The search display controller hides the visibility bar of the search strings.

If you want the area panel to always be available, you have to work a little. Perhaps one of them will help.

How to always show the scope of a UISearchBar?

IOS7: uisearchdisplaycontroller always shows the visibility bar

EDIT:

Have you tried anything in this direction? Assuming you added a search bar to the titleView navigation titleView .

 - (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; CGRect rect = self.navigationItem.titleView.superview.frame; rect.size.height = 88.0f; self.navigationItem.titleView.superview.frame = rect; } 
+1
source

Try setting the searchBar frame: -

 UISearchBar* searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake:(0,0,320,88)]; 
0
source

I installed "Use automatic layout" from xip inspector -> interface builder

This works great with me.

0
source

All Articles