skip to Main Content

I’m trying to open my view controller (with storyboard) which is embedded in a navigation view from the scende delegate

i am doing something like this

let mainStoryboard:UIStoryboard = UIStoryboard(name: "Home", bundle: nil)
        let homePage = mainStoryboard.instantiateViewController(withIdentifier: "HomeViewController") as! HomeViewController
        self.window?.rootViewController = homePage

however i can’t see the navigation bar, i mean, i just see the viewcontroller content
i need to open the navigation view as well

thanks!

2

Answers


  1. Is HomeViewController the name of your UINavigationViewController ?

    If not, then this is expected.

    Give your UINavigationViewController an identifier in the storyboard like you did for HomeViewController and then replace:

    let mainStoryboard:UIStoryboard = UIStoryboard(name: "Home", bundle: nil)
    let homePage = mainStoryboard.instantiateViewController(withIdentifier: "YourNavControllerIdenfier") as! UINavigationController
    self.window?.rootViewController = homePage
    

    Try this and see if it gives you the result you want

    Login or Signup to reply.
  2. Firstly, you need to make your NavigationController as the root vc, not the HomeViewController;

    Secondly, the default Navigation bar style is transparent, if you want to see it, you can customise it, for example:

    self.navigationController?.navigationBar.barStyle = .black
            self.navigationController?.navigationBar.isTranslucent = false
            self.navigationController?.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.white]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search