0

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.

shahtaj khalid
  • 476
  • 7
  • 24
  • I'm not sure I understand your construction properly but I can see that in the first case you present over the window's `rootViewController` while in the second case you present over `self`? What is `self` in that case? Also, the error seems to appear when presenting something over SplashController while the piece of code you give under it is to present the SplashController over I guess the Login so it's not the right code you're showing here – Thomas Sep 13 '17 at 09:11
  • self in the second case is the login view controller @Thomas and i'm editing my question to specify the construction please check. – shahtaj khalid Sep 13 '17 at 09:52

0 Answers0