Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation bar is hiding when i open my search bar

I have a UISearchController embedded in my Navigation Bar and when i click it, the whole navigation bar goes off the screen until i press another area on the screen and then it comes back. Here is a link to the video. (video mightent have uploaded yet so give it some time, the link does work)

    self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
    self.searchController.dimsBackgroundDuringPresentation = NO;
    // Use the current view controller to update the search results.
    self.searchController.searchResultsUpdater = self;
    //Setting Style
    self.searchController.searchBar.barStyle = UIBarStyleBlack;
    self.searchController.searchBar.barTintColor = [UIColor colorWithRed:49.0/255.0 green:49.0/255.0 blue:61.0/255.0 alpha:1.0];
    self.searchController.searchBar.backgroundImage = [UIImage imageNamed:@"BG"];
    self.searchController.searchBar.placeholder = @"Search Artists, Songs, Albums etc.";
    self.searchController.searchBar.keyboardAppearance = UIKeyboardAppearanceDark;
    [self.searchController.searchBar sizeToFit];
    self.definesPresentationContext = YES;
    self.searchController.searchBar.tintColor = self.view.window.tintColor;
    [self.searchController.searchBar setTintColor:[UIColor colorWithRed:(226.0/255.0) green:(56.0/255.0) blue:(83.0/255.0) alpha:(1.0)]];
    self.searchController.searchBar.delegate = self;
    self.navigationItem.titleView = self.searchController.searchBar;
}

- (void)updateSearchResultsForSearchController:(UISearchController *)searchController{
    NSString *searchString = searchController.searchBar.text;
    NSLog(@"You searched for %@", searchString);
    [searchResultsTableView reloadData];
 }

-(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar{
    [self.view addSubview:searchResultsTableView];
}
like image 563
Jefo LInkeo Avatar asked Dec 01 '15 15:12

Jefo LInkeo


People also ask

How do I show hidden navigation bar?

Touch “Settings” -> “Display” -> “Navigation bar” -> “Full screen gestures”.

How to show Navigation bar in android?

Simply just go to Settings -> Display ->Navigation Bar.

What is hidden navigation bar?

Main navigation links are placed under an icon or button and required an action to appear. Such as the hamburger menu, with three stripes you use in the upper corners of website. It was inspired by mobile design patterns, where screen space is small.


1 Answers

You need to add the following

self.searchController.hidesNavigationBarDuringPresentation = NO;

to stop UISearchController hiding the nav bar when activated (ref docs link).

like image 116
AndrewR Avatar answered Sep 30 '22 16:09

AndrewR