sceneDelegate gives a black scree, please guide

In sceneDelegate ,I use the below code in willConnectTo, i get the navigationController but the root view controller is a black screen, i can change its background color etc but i cannot see any view object like label, table etc, please guide, thanks

 guard let winScene = (scene as? UIWindowScene) else { return }

        let vc: ViewController = ViewController()
         let nc = UINavigationController(rootViewController: vc)
         let win = UIWindow(windowScene: winScene)
         win.rootViewController = nc
 window = win

You don’t need to construct new controllers; since you dragged those items into Interface Builder, they’re already constructed for you. My willConnectTo looks like this, which is basically what they show on page 250:

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
    // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
    // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
    guard let _ = (scene as? UIWindowScene) else { return }
    // Create an ItemStore
    let itemStore = ItemStore()
    // Access theItemsViewController and set its item store
    let navController = window!.rootViewController as! UINavigationController
    let itemsController = navController.topViewController as! ItemsViewController
    itemsController.itemStore = itemStore
1 Like

@JonAult -thanks, but i am not using any interface builder, i deleted it and using code to build the whole thing …should i still go ahead and try this code, please guide…

So this is what i did, i deleted the story board, removed the entries as needed to be deleted from plist, then i add the code to my sceneDelegate, with target as ios 13, now the aim is to be able to add a navigationcontroller that i can use to move to other view controllers, in this case i use a ViewController file which come as default as my rootviewcontroller,

Now every thing works well, the naviagtion bar is also visible as you can see , but … this is where the problem come, the rootviewcontroller doesnot show any sub views, like labels, tables etc, only a black screen , i can change its color but again cannot add any sub view to it,

BTW i have the 6th edition hardcopy with me … Thanks again

@JonAult - for some strange reason , i deleted the project and did it all over again with same code, it all works well now, thanks for the help …