gpt4 book ai didi

swift - 警告 : Attempt to present on which is already presenting

转载 作者:行者123 更新时间:2023-11-30 10:09:46 24 4
gpt4 key购买 nike

我想显示警报而不是跳转到主页,但它没有跳转并向我显示此警告:尝试呈现<UITabBarController><SignUpViewController>已经呈现 <UIAlertController>

这是我的代码

let alertController = UIAlertController(title: "Success", message: "Back", preferredStyle: UIAlertControllerStyle.Alert)

alertController.addAction(UIAlertAction(title: "true", style: UIAlertActionStyle.Default,handler: nil))
self.presentViewController(alertController, animated: true, completion:nil)

let MyPage = self.storyboard?.instantiateViewControllerWithIdentifier("tabBarController")
presentViewController(MyPage!, animated: true, completion: nil)

我看到一些答案让我使用viewdidappear或其他东西,但我仍然很困惑,不知道该怎么做,我花了几个小时不是,请帮我解决这个问题,非常感谢!

最佳答案

您可以将您的presentViewController函数放入警报完成处理程序中

alertController.addAction(UIAlertAction(title: "true", style: UIAlertActionStyle.Default,handler: nil))

如果您在处理程序中放入一些代码,则当您单击“true”按钮时执行的代码。

例如,

alertController.addAction(UIAlertAction(title: "true", style: UIAlertActionStyle.Default,handler: {
(alert: UIAlertAction) -> Void in
let MyPage = self.storyboard?.instantiateViewControllerWithIdentifier("tabBarController")
self.presentViewController(MyPage!, animated: true, completion: nil)
}))

关于 swift - 警告 : Attempt to present <UITabBarController> on <SignUpViewController> which is already presenting <UIAlertController>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33602930/

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