gpt4 book ai didi

ios - 通过 Appdelegate 调用时展开 View Controller 时出错

转载 作者:行者123 更新时间:2023-11-28 08:05:39 25 4
gpt4 key购买 nike

因此,当应用程序到达前台时,我试图在当前 vc 上显示密码 VC。当前,在 passcodeVC(我试图在顶部显示的 VC)上具有此功能:

func present() {
print("calling present")
if let passcodeVC = storyboard?.instantiateViewController(withIdentifier: "IdlePasscodeVC") {
passcodeVC.modalPresentationStyle = .overCurrentContext
present(passcodeVC, animated: true, completion: nil)
} else {
print("there was an error unwrapping")
}
}

当应用到达前台时,我通过 AppDelegate 调用它:

func applicationWillEnterForeground(_ application: UIApplication) { 
print("app entered foreground")
let storyboard = UIStoryboard(name: "Main", bundle: nil)
if let passcodeVC = storyboard.instantiateViewController(withIdentifier: "LockVC") as? IdlePasscodeViewController{
passcodeVC.present()
}
}

修复了一个问题;但现在我收到错误消息“警告:尝试显示其 View 不在窗口层次结构中!”

有办法解决这个问题吗?还是有人可以告诉我更好的方法(我已经阅读了通知中心并且可以使用监听器,但我不知道从哪里开始)。

希望密码 VC 在上次打开的屏幕顶部显示自己,这样当密码正确时,它可以自行关闭

可能的替代方法会有所帮助。

编辑:是否可以使用此解决方案?

Attempt to present ViewController whose view is not in the windows hierarchy

最佳答案

检查这个我认为可以在某种程度上帮助你

func applicationWillEnterForeground(_ application: UIApplication) { 
print("app entered foreground")
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
if let passcodeVC = storyboard?.instantiateViewController(withIdentifier: "IdlePasscodeVC") as? IdlePasscodeViewController{
passcodeVC.present()
}
}

希望对你有帮助

关于ios - 通过 Appdelegate 调用时展开 View Controller 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45224273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com