0

I want to change the navigation's root view controller programmatically using objective c. I am using a storyboard. I tried to change it in-app delegate but didn't work, there's something new introduced called scene delegate where I believe I can change the root from there, but I found no resources for that matter. Can anyone help?

Fahim Uz Zaman
  • 444
  • 3
  • 6
VeeN
  • 11
  • 1

1 Answers1

0

Use below code:

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

    var window: UIWindow?
    
    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    
        if let windowScene = scene as? UIWindowScene {
            let window = UIWindow(windowScene: windowScene)
            window.rootViewController = MyRootViewController()
            self.window = window
            window.makeKeyAndVisible()
        }
     }

Reference: https://www.andrewcbancroft.com/blog/ios-development/ui-work/accessing-root-view-controller-ios13-scenedelegate/

And: How set rootViewController in Scene Delegate iOS 13

Daljeet
  • 1,573
  • 2
  • 20
  • 40