Navigation bar not showing iOS swift

前端 未结 7 1469
醉话见心
醉话见心 2021-02-18 13:24

I am having multiple view controller in my application. I want to hide navigationbar in my first view controller. So I use the following code to hide the navigation

相关标签:
7条回答
  • 2021-02-18 13:39

    do like in viewcontroller based hidden using Swift 4.0

    To hide navigationController in viewWillAppear

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

    To unhide navigationController in viewWillDisappear

    override func viewWillDisappear(animated: Bool)
    {
        super.viewWillDisappear(animated)
        self.navigationController?.isNavigationBarHidden = false
    }
    
    0 讨论(0)
  • 2021-02-18 13:39

    If you need to have this navigation bar hidden only in this controller, the best way is to show it in viewWillDisappear() and hide in viewWillAppear().

    0 讨论(0)
  • 2021-02-18 13:40

    It's too late to reply and there are other good answers but I would like to share what worked for me.

    let controller = self.storyboard?.instantiateViewControllerWithIdentifier("HomeVC")
        self.navigationController!.pushViewController(controller!, animated:true)
    
    0 讨论(0)
  • 2021-02-18 13:52
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    
        // Hide the navigation bar on the this view controller
        self.navigationController?.setNavigationBarHidden(true, animated: animated)
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
    
        // Show the navigation bar on other view controllers
        self.navigationController?.setNavigationBarHidden(false, animated: animated)
    }
    
    0 讨论(0)
  • 2021-02-18 13:53

    in viewDidLoad method of the view controller in which you don't want to show navigation bar add the line

    navigationController.navigationBarHidden = true
    

    you are presently hiding in all view controllers

    Edit: You are presenting view controller instead it should be

    self.navigationController!.pushViewController(controller) 
    
    0 讨论(0)
  • 2021-02-18 13:53

    I am having same requirement in my swift project.

    this is how I have handled Navigation bar

    Make sure your first screen is embedded into Navigation controller

    example we have two screens A and B

    In screen A you need to hide navigation bar in viewWillAppear

    override func viewWillAppear(animated: Bool)
        {
             super.viewWillAppear(animated)
    
            //hide navigation for screen A
            self.navigationController?.navigationBarHidden = true
        }
    

    for enabling Navigation in screen B you need to add below code in screen A

    override func prepareForSegue(segue: (UIStoryboardSegue!), sender: AnyObject!)
        {
            if (segue.identifier == "screen B's segue identifier here")
            {
               //enable navigation for screen B       
                navigationController?.setNavigationBarHidden(navigationController?.navigationBarHidden == false, animated: true)
            }
    
        }
    

    Using above style, I can enable or disable navigation bar for specific screen, whenever I want

    0 讨论(0)
提交回复
热议问题