简体   繁体   English

在推上隐藏导航栏不起作用

[英]Hide navigationBar on push not working

I'm trying to push to a viewController, however i wan't to hide the navigationBar in this viewController. 我正在尝试推送到viewController,但是我不想在此viewController中隐藏navigationBar。 However it does not seem to apply even though i've set below before pushing? 但是,即使我在推送之前设置了以下内容,它似乎也不适用?

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    let cameraViewController = ALCameraViewController(croppingEnabled: false) { image in
        // Do something with your image here.
        // If cropping is enabled this image will be the cropped version
    }
    cameraViewController.navigationController?.setNavigationBarHidden(true, animated: false)
    self.navigationController?.pushViewController(cameraViewController, animated: true)


}

the alternate way . 替代方式。 you can directly hide/show the navigation bar on cameraViewController 您可以直接在cameraViewController上隐藏/显示导航栏

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES];   //it hides  
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO];    // it shows
}

--- In swift --- ---迅速---

override func viewWillAppear(animated: Bool) {
    self.navigationController?.navigationBarHidden = true
}

override func viewWillDisappear(animated: Bool) {
    self.navigationController?.navigationBarHidden = false
}

--- Swift 4.0 --- -Swift 4.0-

override func viewWillAppear(_ animated: Bool) {
    self.navigationController?.isNavigationBarHidden = true
}

override func viewWillDisappear(_ animated: Bool) {
    self.navigationController?.isNavigationBarHidden = false
}

Your code isn't working because trying to access navigationController property when it's equal to nil (quote from docs: "This property is nil if the view controller is not embedded inside a navigation controller.") 您的代码无法正常工作,因为尝试在等于nil时尝试访问navigationController属性(引自文档:“如果视图控制器未嵌入导航控制器中,则此属性为nil。”)

So, if you need to hide navigation bar in specified view controller use code from Keyur, or, if you can't modify code of this view controller and can't subclass it, you can hide/show navigation bar inside - navigationController:willShowViewController:animated: in your navigation controller delegate 因此,如果您需要在指定视图控制器中隐藏导航栏,请使用Keyur中的代码,或者,如果您不能修改该视图控制器的代码并且不能对其进行子类化,则可以在内部隐藏/显示导航栏- navigationController:willShowViewController:animated:在您的导航控制器委托中

In the storyboards you need select your ViewController and go to Editor->Embebed In->Navigation Controller. 在情节提要中,您需要选择ViewController并转到Editor-> Embedbed In-> Navigation Controller。 I have two Navigation Controllers, one in the root and another follow my ViewController. 我有两个导航控制器,一个在根目录中,另一个在我的ViewController之后。 And the navigationBarHidden true or false, works perfectly for me, in my case. 而对于我来说,navigationBarHidden是true还是false完全适合我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM