我有一个带登录视图的应用。在appDelegate中,我检查用户是否使用密码锁定应用程序。如果他这样做,他会进入登录视图。 (在didFinishLaunchingWithOptions中调用的代码)
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let nav = storyboard.instantiateViewControllerWithIdentifier(Views.LoginVC.rawValue)
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window?.rootViewController = nav
self.window?.makeKeyAndVisible()
登录后,我在不同的导航控制器中显示实际内容。
let vc = self.storyboard?.instantiateViewControllerWithIdentifier(Views.MainVC.rawValue)
let rootVC = UINavigationController(rootViewController: vc!)
self.presentViewController(rootVC, animated: false, completion: nil)
关闭应用并再次输入时,appDelegate将再次检查用户是否使用密码。如果是,则再次调用第一个代码(我检查过,代码被调用)(从applicationWillEnterForeground调用的代码)。但是,他没有进入登录视图,而是停留在主要内容视图中。如果他再次离开,控制台中会弹出一条错误消息。
2016-04-25 20:50:52.714 Point[7222:123809] Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.
我需要更改什么,以便应用程序在返回时再次显示登录视图?如何避免此错误消息?
更新
我刚刚通过调用applicationDidBecomeActive中的代码而不是didFinishLaunchingWithOptions来解决我的问题。我不知道为什么会这样,但它确实有效!