I'm creating a UISearchViewController
and I wish to put the UISearchBar
in the navigation controller's navigation item. Here's how I did it with no 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;
Am I missing out anything or doing something wrong here?
Edit: This and this is exactly what I'm aiming for.
Try with 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;
The scope bar will only appear when the search bar is active. The search display controller is hiding the search bars scope bar.
If you want the scope bar always available, you'll have to do a little hack work. Maybe one of these will help.
How to have UISearchBar scope bar always visible?
IOS7 : uisearchdisplaycontroller always show scope bar
EDIT:
Have you tried something in this direction? Assuming you have added the search bar to the navigation bar's titleView
.
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
CGRect rect = self.navigationItem.titleView.superview.frame;
rect.size.height = 88.0f;
self.navigationItem.titleView.superview.frame = rect;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With