-1

Here is my code to present a ViewController from app delegate in swift 5, I have done everything the same as everyOne else But the new ViewController is not shown when app is launched.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: Bundle.main)
        let welcome  = mainStoryboardIpad.instantiateViewController(withIdentifier: "Welcome") as! WelcomeScreen

        self.window = UIWindow(frame: UIScreen.main.bounds)
        self.window?.rootViewController = welcome
        self.window?.makeKeyAndVisible()
 return true
}

1 Answers1

0

Put it in

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: Bundle.main)
        let welcome  = mainStoryboardIpad.instantiateViewController(withIdentifier: "Welcome") as! WelcomeScreen
        self.window = UIWindow(frame: UIScreen.main.bounds)
        self.window?.rootViewController = welcome
        self.window?.makeKeyAndVisible()

        return true 
}

UPDATE: If it is not working try:

 if let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: Bundle.main){
      if let welcome  = mainStoryboardIpad.instantiateViewController(withIdentifier: "Welcome") as! WelcomeScreen{
           //Does it come here?
           self.window = UIWindow(frame: UIScreen.main.bounds)
           self.window?.rootViewController = welcome
           self.window?.makeKeyAndVisible()        
     }
 }

Make sure you actually get in to the body if most inner if which is if let welcome = mainStoryboardIpad.instantiateViewController(withIdentifier: "Welcome") as! WelcomeScreen