Attempt to present <> on <> whose view is not in the window hierarchy

323 views Asked by At

I'm using this code in AppDelegate where on some condition it either opens login screen or splash screen. like below

if (mobile != nil && keepMe == true) { // skip login

        let initialViewControlleripad : UIViewController = mainStoryboardIpad.instantiateViewController(withIdentifier: "SplashController") as UIViewController
        self.window?.rootViewController = initialViewControlleripad
        self.window?.makeKeyAndVisible()
    }
    else {// Show login

        let initialViewControlleripad : UIViewController = mainStoryboardIpad.instantiateViewController(withIdentifier: "LoginScreen") as UIViewController
        self.window?.rootViewController = initialViewControlleripad
        self.window?.makeKeyAndVisible()
        print("Login!")
    }

when it open splash screen first: from splash screen it goes to main Menu screen like this

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
    let vc = self.view.window?.rootViewController
    let ViewController = storyBoard.instantiateViewController(withIdentifier: "toMenu")
   vc?.present(ViewController, animated:true, completion:nil)

and it is opened fine. BUT, when from app delegate it open the login screen first and from login screen on a button click it moves to splash and then to main menu it keeps giving this warning,

 Warning: Attempt to present <SWRevealViewController: 0x7faac8839000> on <AppPhaseOne.Splash: 0x7faac7529530> whose view is not in the window hierarchy!

code of login screen:

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
                let ViewController = storyBoard.instantiateViewController(withIdentifier: "SplashController")
                self.present(ViewController, animated:true, completion:nil)

So the construction of viewControllers are like this:

app delegate: Splash -> mainMenu (working fine)
app delegate: Loign -> Splash -> mainMenu (giving the warning)

I know there are many solutions available for this problem, i have tried many solutions available and none of it worked.

0

There are 0 answers