gpt4 book ai didi

ios - 尽管 UIAlertController 在 View 层次结构中,但呈现一个 ViewController

转载 作者:行者123 更新时间:2023-11-29 01:36:43 25 4
gpt4 key购买 nike

我想在出现 alertControllerpresentViewController

我想,如果用户现在按下“确定”按钮,我想在 PushNotification 上显示来自 AppDelegate 的 ViewController

我开始知道 UIAlertController 是在不同的线程上呈现的,因此希望在用户按下“确定”按钮并移动到主线程后呈现 ViewController ,如下所示:

func presentRScreenFromRootViewController()
{

let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let rViewController = storyboard.instantiateViewControllerWithIdentifier("rsh") as! R_SVC
dispatch_async(dispatch_get_main_queue(),{

self.window?.rootViewController?.presentViewController(rViewController, animated: true, completion: nil)


});

}

但是我得到的警告是:

 Attempt to present <BB.R_SVC: 0x15b983600>  on
<SWRevealViewController: 0x15652df00> which is already presenting
<UIAlertController: 0x15b4f2dd0>

这是因为 View Controller 正在呈现警报 Controller 。其他时候它工作得很好。我的 rootViewController 更改并移动到下一个屏幕。但是当有 UIAlertController 时,我会收到警告,因为尝试呈现不在 View 层次结构中的 View Controller

我做错了什么?

最佳答案

创建 UIAlertController 时,将 VCpresenting 代码放入 UIAlertAction 中,如下所示

let alert = UIAlertController(title: "your title", message "move to next VC?", preferredStyle: UIAlertController: UIAlertControllerStyle.Alert)
let action: UIAlertAction = UIAlertAction(title: "yes move to next VC", style: UIAlertActionStyle.Default) {action -> Void in
let rViewController = storyboard.instantiateViewControllerWithIdentifier("rsh") as! R_SVC
self.presentViewController(rViewController, animated: true, completion: nil) })
alert.addAction(defaultAction)

self.presentViewController(alert, animated: true, completion: nil)

编辑:也许尝试Dismiss all UIAlertControllers currently presented .

关于ios - 尽管 UIAlertController 在 View 层次结构中,但呈现一个 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32880605/

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