Navigation bar not showing iOS swift

前端 未结 7 1465
醉话见心
醉话见心 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: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

提交回复
热议问题