How to hide Navigation Controller in Root View?

感情迁移 提交于 2019-12-23 09:05:20

问题


Please, help me to hide navigation controller in root view. I've found the solution to write [navigationController setNavigationBarHidden:YES] in every view controller which I need. Well, it works but only for the first time: I run application, in root view I don't have navigation, then I go to the second view – the navigation appears, OK. But then I press "Back" in navigation controller, and navigation from root view hasn't disappear. I work with xib.


回答1:


In rootViewController

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

In second View(next to rootViewController)

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



回答2:


Try this out

Use this line of code on all your view controllers

[navigationController setNavigationBarHidden: YES animated:YES]; 

If no animation is needed you can do animated:NO and add this code in viewDidLoad or put it viewWillAppear or viewDidAppear.

In your case

[navigationController setNavigationBarHidden:YES animated:NO];

on your rootViewController, and

[navigationController setNavigationBarHidden:NO animated:YES]; 

on your other viewControllers




回答3:


Hide Navigation bar all view controller's view will appear method.

-(void)viewWillAppear:(BOOL)animated
{ 
 [super viewWillAppear:animated];
 [navigationCOntroller setNavigationBarHidden:YES animated:animated];
}



回答4:


I believe you are using tab bar controller.

Your code is working for first view controller as you have code there only. For second view controller, it goes default and hence for second view controller you see navigation bar.

To hide navigation bar for all view controller, put hidden code in all view controllers viewWillAppear

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



回答5:


For Swift developers

Swift 4.2

RootViewController.swift

class RootViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func viewWillAppear(_ animated: Bool) {
        self.navigationController?.setNavigationBarHidden(true, animated: false)
    }
}

NextViewController.swift

class NextViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        self.navigationController?.setNavigationBarHidden(false, animated: false)
    }
}


来源:https://stackoverflow.com/questions/19421962/how-to-hide-navigation-controller-in-root-view

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