Why I can't see Launch Screen when change Root View in swift5?

the problem I have is to remove the root arrow on the story board and set up the root view in the **AppDelegate** file to dynamically change the RootView.



There is no problem moving the root view, but the existing `splashScreen(Launch Screen)` is not visible. Why can't you see it? How can I see the `splashScreen(Launch Screen)` and go to the root view?



**Main.Storyboard**



https://ifh.cc/g/0LXBV.png



**Login.Storyboard,**



https://ifh.cc/g/CtlFX.png



**Launch.Storyboard**



https://ifh.cc/g/pps62.png





**Move Root Screen in AppDelegate.swift**



~~~swift

var window: UIWindow?


    func switchStartUI() {
        let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let viewController = mainStoryboard.instantiateViewController(withIdentifier: "StartViewController")
        self.window?.rootViewController = viewController
    }
   
    func switchToMainUI() {
        let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let viewController = mainStoryboard.instantiateViewController(withIdentifier: "NavigationController")
        self.window?.rootViewController = viewController
    }
   
    func switchLoginUI(_ pushtype : String) {
        let loginStoryboard = UIStoryboard(name: "Login", bundle: nil)
        let viewController = loginStoryboard.instantiateViewController(withIdentifier: "MainLoginController") as! MainLoginController
        viewController.pushType = pushtype
        self.window?.rootViewController = viewController
    }


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        self.window = UIWindow(frame: UIScreen.main.bounds)
      if let screenData : String = LocalStorage.get("ScreenView") as? String {
            switch (screenData) {
            case "success":
                switchToMainUI()
            case "success1":
                switchLoginUI("")
            case "success2":
                switchLoginUI("")
            default:
                switchStartUI()
            }
        } else {
            switchStartUI()
        }
       
        self.window?.makeKeyAndVisible()
       
        return true
    }

~~~



I want to see the splash screen and move on to the root view



There is already an image on my splash screen. It worked normally. But I can't see the splash screen after dynamically modifying the root view. I'm the same



help me a lot

Accepted Reply

I don't understand much about swift and xcode. That's why I didn't answer your question well.


First, I used the storyboard to create a view on the screen, and then I registered the view controller that I created on the story board.


I solved the problem. The solution was simple. Launch.Added root arrow to storyboard. My story board didn't have a root arrow.

Replies

If you have defined a launch storyboard, it will appear (just for the time needed for the rest to load, which may be very short).


If you remove the launch storyboard, you will go directly to the initial view (maybe after some black screen moment).

Note: I don't know whether appstore review requests a launchStoryboard.


Why do you create 3 different storyboards and not just 3 ViewControllers ? Your story look more like VC than SB.

Is it wrong for me to set up a root view? I have a LaunchStoryboard. I can't show you my splash screen storyboard, but I have it. However, go to the root view after the black or white screen.

Is it wrong for me to set up a root view?

What is this RootView ? Is it just a view controller ? Or some special viewController (for navigation ?)

Where is the RootView ? It should be in the MainStroyboard.


I have a LaunchStoryboard. I can't show you my splash screen storyboard, but I have it.

And do you see it when app launches ? Have you anything inside ? You should, at least to test.


However, go to the root view after the black or white screen.

You get a white screen (probably the view of the launchStoryboard).


And you did not answer my question:

Why do you create 3 different storyboards and not just 3 ViewControllers ? Your storyboards look more like VC than SB.

I don't understand much about swift and xcode. That's why I didn't answer your question well.


First, I used the storyboard to create a view on the screen, and then I registered the view controller that I created on the story board.


I solved the problem. The solution was simple. Launch.Added root arrow to storyboard. My story board didn't have a root arrow.

Some terminology.


It is not a question of root view controller, but initial view controller.

TYou had no initial view controller defined, so, of course, the app did not know which view to start with.