我在 AppDelegate 中使用此代码,在某些情况下它会打开登录屏幕或启动屏幕。像下面
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!")
}
当它首先打开启动屏幕时:从启动屏幕进入主菜单屏幕,如下所示
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)
它打开得很好。但是,当从应用程序委托它首先打开登录屏幕并从登录屏幕上单击按钮时,它会移动到启动画面,然后到主菜单,它会一直发出这个警告,
Warning: Attempt to present <SWRevealViewController: 0x7faac8839000> on <AppPhaseOne.Splash: 0x7faac7529530> whose view is not in the window hierarchy!
登录界面代码:
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let ViewController = storyBoard.instantiateViewController(withIdentifier: "SplashController")
self.present(ViewController, animated:true, completion:nil)
所以viewControllers的构造是这样的:
app delegate: Splash -> mainMenu (working fine)
app delegate: Loign -> Splash -> mainMenu (giving the warning)
我知道有很多解决方案可以解决这个问题,我尝试了很多可用的解决方案,但都没有奏效。