gpt4 book ai didi

ios - "Attempt to present while already presenting"检查后还出现?

转载 作者:行者123 更新时间:2023-11-28 15:36:36 26 4
gpt4 key购买 nike

 let appDelegate = UIKit.UIApplication.shared.delegate!

if let tabBarController = appDelegate.window??.rootViewController as? UITabBarController {
let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
let signInVC = storyboard.instantiateViewController(withIdentifier: "SignInVC") as! SignInVC

guard !signInVC.isBeingPresented else {
log.warning("Attempt to present sign in sheet when it is already showing")
return
}

signInVC.modalPresentationStyle = UIModalPresentationStyle.formSheet

tabBarController.present(signInVC, animated: true, completion: nil)
}

尽管出现了 signInVC,此代码仍可被多次调用。我已经添加了这张支票:

 guard !signInVC.isBeingPresented else {
log.warning("Attempt to present sign in sheet when it is already showing")
return
}

但它似乎并不能防止这个错误:

Warning: Attempt to present <App.SignInVC: 0x101f2f280>  on <UITabBarController: 0x101e05880> which is already presenting <App.SignInVC: 0x101f4e4c0>

最佳答案

你的 guard 不是有效的支票。 isBeingPresented 在尚未呈现的全新 View Controller 实例上被调用。所以 isBeingPresented 将始终为 false。除此之外,该属性只能在 View Controller 的 view[Will|Did]Appear 方法中使用。

您要检查的是 tabBarController 是否已经呈现另一个 View Controller 。

最后,仅在应显示时创建和设置登录 View Controller 。

let appDelegate = UIKit.UIApplication.shared.delegate!

if let tabBarController = appDelegate.window?.rootViewController as? UITabBarController {
if tabBarController.presentedViewController == nil {
let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
let signInVC = storyboard.instantiateViewController(withIdentifier: "SignInVC") as! SignInVC
signInVC.modalPresentationStyle = UIModalPresentationStyle.formSheet

tabBarController.present(signInVC, animated: true, completion: nil)
}
}

关于ios - "Attempt to present while already presenting"检查后还出现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44222543/

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