Keeping UINavigationController's navigationBar hidden after UISearchDisplayController selection

后端 未结 5 2059
孤独总比滥情好
孤独总比滥情好 2021-02-04 05:16

I have a UISearchDisplayController setup with a UITableViewController which is nested inside a UINavigationController. When a selection o

5条回答
  •  一个人的身影
    2021-02-04 05:55

    This may not be the most elegant solution, but I believe it does exactly what you'd want it to. I came across a similar problem, and my solution was to have a method which hides the navigation bar, which is called after a delay of 0 seconds as follows.

    The method that is called is:

    -(void) hideNavBar {
        if (self.navigationController.navigationBar.hidden == NO)
        {
            [self.navigationController setNavigationBarHidden:YES animated:YES];
        }
    }
    

    Then in the viewDidLoad method, I have the following:

    [self performSelector:@selector(hideNavBar) withObject:nil afterDelay:0.0];
    

    This works and removes the navigation bar in one instantaneous swoop. You can amend the delay time if you want the animation or for it to be removed after a delay. I tried [self hideNavBar] but that simply did not work, so sticking to what I have above.

    Hope this helps, and if someone has a more elegant solution, I'm interested!

提交回复
热议问题