Jefo LInkeo
Jefo LInkeo

Reputation: 53

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];
}

Upvotes: 5

Views: 1972

Answers (1)

AndrewR
AndrewR

Reputation: 10889

You need to add the following

self.searchController.hidesNavigationBarDuringPresentation = NO;

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

Upvotes: 12

Related Questions