开发者

Search Display Controller to not hide navigation bar when search bar is tapped

开发者 https://www.devze.com 2022-12-13 19:16 出处:网络
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:YE

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

精彩评论

暂无评论...
验证码 换一张
取 消