Home > Software engineering >  Entrypoint is not changing
Entrypoint is not changing

Time:11-14

I'm pretty new to Swift and Xcode and I can't find an answer online, so I hope you guys can help me.

I'm trying to change the screen when someone is logged in. I'm trying to change the default entry point to the other screen, but somehow it does not work.

This is in the AppDelegate where I am trying to change the entry point:

var window: UIWindow?
    
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    let mainStoryboard = UIStoryboard(name: "Main" , bundle: nil)
    let initialViewController = mainStoryboard.instantiateViewController(withIdentifier: "homePage") as! HomePageController
    window?.rootViewController = initialViewController
    window?.makeKeyAndVisible()
    return true
}

Here I have set the ID for the screen/controller I want to replace with the default entry point (the default entry point is my login screen).

enter image description here

CodePudding user response:

Try to do it in sceneDelegate like that:

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    guard let windowsScene = (scene as? UIWindowScene) else { return }
    window = UIWindow(windowScene: windowsScene)
    window?.makeKeyAndVisible()
    let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let initialViewController = mainStoryboard.instantiateViewController(withIdentifier: "homePage") as! HomePageController
    window?.rootViewController = initialViewController
}
  • Related