Search Display Controller to not hide navigation bar when search bar is tapped
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
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];
}
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];
}
精彩评论