0

I use Search Display Controller to do the search. I follow the TableSearch sample from Apple.

In searchBarTextDidBeginEditing I put [self.searchDisplayController setNavigationBarHidden:NO animated:YES] to keep navigation bar showing, but this doesn't work. Navigation bar gets pushed to the top when the keyboard shows.

Is there a way to keep navigation bar staying on the page when the keyboard is first shown?

Thanks

Ted

Titouan de Bailleul
  • 12,920
  • 11
  • 66
  • 121
  • Check out my answer over here: http://stackoverflow.com/questions/2813118/prevent-a-uisearchdisplaycontroller-from-hiding-the-navigation-bar – stigi Jul 15 '10 at 16:42

2 Answers2

0

This seem to solve it for me. Tested in both iOS5/6.1. No visual issues that I could see.

- (void)viewDidAppear
{
    [super viewDidAppear];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillAppear:) name:UIKeyboardWillShowNotification object:nil];
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)keyboardWillAppear:(NSNotification *)notification
{
    [self.navigationController setNavigationBarHidden:NO animated:NO];
}

-(void)viewDidLayoutSubviews{
    [self.navigationController setNavigationBarHidden:NO animated:NO];
}
Daniel Ryan
  • 6,976
  • 5
  • 45
  • 62
-1

There may be a better solution, but this is what I'm using right now. The navigation bar does get covered up at first, but this makes it slide back in right away:

- (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller {
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}
Jim Rhoades
  • 3,310
  • 3
  • 34
  • 50
  • it din't worked buddy. I additionally used: `-(void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller { NSLog(@"the hack worked"); [self.navigationController setNavigationBarHidden:NO animated:YES]; }` – geekay Feb 15 '12 at 17:20
  • I still have problem. I added the search bar as header for section. Using the above work around, Though the navigation bar is visible, the search bar goes under navigation bar and becomes invisible. When you drag the table I can see search bar now visible and again goes under the navigation bar after releasing the drag. –  Nov 07 '12 at 10:12