How to hide/disable only the first uinavigationbar?

六月ゝ 毕业季﹏ 提交于 2019-12-03 11:34:24

In most of my applications I have a custom UIViewController class that I derive all other custom controllers from. In some of these, I added a method like navigationBarInitiallyHidden to the base class that other classes can override. The default result depends on the nature of the application.

In the delegate of the navigation controller, when a controller is being shown that implements that method, the delegate hides or shows the navigation controller accordingly. Since I animate the hide or show, I check the current state and do nothing if no change is needed.

You could do something simpler in your delegate method. If the controller being shown is the root controller, hide the navigation bar, otherwise show it if it is hidden.

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
  if ( viewController == rootController ) {
    [navigationController setNavigationBarHidden:YES animated:animated];
  } else if ( [navigationController isNavigationBarHidden] ) {
    [navigationController setNavigationBarHidden:NO animated:animated];
  }
}
yasha02

You can hide the navigation bar: [self.navigationController setNavigationBarHidden:YES]; and where you want to show the navigation bar again [self.navigationController setNavigationBarHidden:NO];

hide/disable

self.navigationController.navigationBarHidden = YES;

show/Enable

self.navigationController.navigationBarHidden = NO;

You can hide navigation bar by using bellow code. Below code will hide navigationbar at the time of viewWillAppear.

Objective C

-(void)viewWillAppear:(BOOL)animated
 {
        [[self navigationController] setNavigationBarHidden:YES animated:NO];
 }

Swift

self.navigationController?.setNavigationBarHidden(true, animated: animated)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!