UISearchDisplayController hiding navigation bar

前端 未结 4 645
青春惊慌失措
青春惊慌失措 2021-01-07 01:24

I am seeing a weird situation. I have put a search bar in the navigation bar and have linked a UISearchDisplayController with the search bar. Now, the search display control

4条回答
  •  温柔的废话
    2021-01-07 01:42

    okay and just in case, if somebody faces this kind of situation. I implemented a work around for the above situation.

    The problem was that the when I popped view controller B from the navigation stack, the searchDisplayController was still active in view controller A. Now, the searchDisplayController assumes that the search bar should always be below the navigation bar (AFAIK). Therefore, it did not displayed the navigation bar when view controller A was again displayed. To fix that, I wrote the following code in the viewWillLayoutSubviews function of view controller A.

    -(void)viewWillLayoutSubviews
    {
        if(self.searchDisplayController.isActive)
        {
            [UIView animateWithDuration:0.001 delay:0.0 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
                [self.navigationController setNavigationBarHidden:NO animated:NO];
            }completion:nil];
        }
        [super viewWillLayoutSubviews];   
    }
    

    The above provides a animation so that when the user pops view controller B, the view controller A shows its search bar activated (if the user had earlier tried to search for anything before going to view controller B). It is not a very smooth transition but it works :) ....

    Note :- Do not use the above code in viewDidLoad or viewDidAppear functions as it might provide an undesirable animation.

提交回复
热议问题