Unable to hide navigation bar that suddenly appear after popViewController in SearchDisplayCotroller

718 views Asked by At

I have a problem where a navigation bar suddenly appear after popViewController is called when SearchDisplayCotroller is still active.

enter image description here

I am implementing a simple tableview with searching capability. Above is my storyboard.

On the first view, i've implemented as per below. So, the navigation bar will be always hidden for the first view.

- (void) viewWillAppear:(BOOL)animated{
[self.navigationController setNavigationBarHidden:YES animated:NO];
}

Button press will push the next table view controller with the below code so that the navigation bar will be visible.

- (void) viewWillAppear:(BOOL)animated{
    [self.navigationController setNavigationBarHidden:NO animated:NO];
}

Everything works fine until i implemented the below code.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self.navigationController popViewControllerAnimated:YES];
} 

When popViewControllerAnimated:YES while the SearchDisplayController is still active, a weird white navigation bar appears and my viewWillAppear is unable to hide the bar. Is this a bug or is there any way to prevent this bar from appearing?

The gif below may also give you the idea what did happen. Thanks!

Look at the white navigation bar that appeared

2

There are 2 answers

0
Wazir Aminnudin On BEST ANSWER

Try this

-(void) viewWillDisappear:(BOOL)animated {
  [super viewWillDisappear:animated];
  // To check if searchDisplayController still active
  if ([searchDisplayController isActive]) {
    [searchDisplayController setActive:NO];
  }
}
0
anthonyliao On

Try inactivating your UISearchDisplayController by calling setActive:NO animated:NO before you call [self.navigationController popViewControllerAnimated:YES];

https://developer.apple.com/LIBRARY/IOS/documentation/UIKit/Reference/UISearchDisplayController_Class/index.html#//apple_ref/occ/instm/UISearchDisplayController/setActive:animated: