Home > Net >  open viewcontroller embedded in navigation view in swift UIKit
open viewcontroller embedded in navigation view in swift UIKit

Time:02-24

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!

CodePudding user response:

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

CodePudding user response:

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]
  • Related