0

So in my last question, I was trying to instantiate from the AppDelegate, but it wasn't working, so after doing more research I kept seeing SceneDelegate and decided to give it a try. To my surprise it worked, but not really how I wanted it to.

So here's the normal image of the viewController upon login. normal VC

Don't mind the whitespace, i'm having trouble with auto-layout and it's something i will fix in the future. I want this exact image to be shown when the VC is instantiated from SceneDelegate.swift with buttons, navigation bar, user interaction and everything shown properly.

Now when I run this block of code in the SceneDelegate willConnectTo() method...

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).
    self.window = self.window ?? UIWindow()

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
     let auth = Auth.auth()

    
    auth.addStateDidChangeListener { (_, user) in

        if let user = user {
            let alreadyLoggedInViewController = storyboard.instantiateViewController(withIdentifier: Constants.StoryboardIDs.StudentEventDashboardStoryboardID) as! StudentSegmentedTableViewController
            self.window!.rootViewController = alreadyLoggedInViewController
            self.window!.makeKeyAndVisible()
        }



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

I end up with this ...

messedup VC

I was actually happy to see it because my code finally worked, but it doesn't show the navigation bar with the bar button item and that kinda crushed the happiness. The segmented control is still interactive and the tableview still refreshes which is great, but I just want my normal VC back so a user can normally use the app and see all the other UI. If anybody can help with this, it would be such a big help to me. Thanks in advance.

dsonawave
  • 137
  • 2
  • 12

1 Answers1

0

Awesome, all I needed to do was add this line of code ..

 let navigationizedVC = UINavigationController(rootViewController: alreadyLoggedInViewController)

Then just do this ...

             self.window!.rootViewController = navigationizedVC

Works perfect.

dsonawave
  • 137
  • 2
  • 12