Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Changing the initial controller not working

I am creating an app in which functionality like if a user is logged in, the app will go to home pages, otherwise it will go to login pages. So I’m adding the below code in AppDelegate to change the initial controller, but my code is not working.

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

        let navigationController : UINavigationController =           storyboard.instantiateInitialViewController() as! UINavigationController
        let rootViewController:UIViewController = storyboard.instantiateViewController(withIdentifier: "MyViewController") as! MyViewController
            navigationController.viewControllers = [rootViewController]
        self.window?.rootViewController = navigationController
        self.window?.makeKeyAndVisible()

I want to change the initial controller if user is logged in. I want to achieve my requirement programmatically not using storyboard

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can solve your Problem by removing Scene Delegate, you can comment the whole class and then also comment the methods of Scene Delegate from App Delegate Class like :

/*
    func application(_ application: UIApplication, 
    configurationForConnecting connectingSceneSession: UISceneSession, 
    options: UIScene.ConnectionOptions) -> UISceneConfiguration {
   
       return UISceneConfiguration(name: "Default Configuration", 
        sessionRole: connectingSceneSession.role)
   }

    func application(_ application: UIApplication, 
     didDiscardSceneSessions 
         sceneSessions: Set<UISceneSession>) {
    }
*/
 

and remove the Property Application Scene Manifest from info.pist
now run your code you will be able to change the initial Controller. actually when we have both classes then Scene Delegate will handle these things so by removing scene Delegate , AppDelegate will work

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading