0

我想在presentViewController出现时alertController

我想,如果用户现在按下 Ok 按钮,我想ViewController在 PushNotification 上显示来自 AppDelegate 的消息。

我开始了解在UIAlertController不同线程上呈现的 SO,因此希望ViewController在用户按下 Ok 按钮并移至主线程后呈现如下:

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>

这是因为视图控制器正在呈现警报控制器。其他时候它运行良好..我的 rootViewController 更改并移动到下一个屏幕..但是当有 UIAlertController 时,我收到警告,因为尝试呈现不在视图层次结构中的视图控制器

我究竟做错了什么?

4

1 回答 1

1

创建 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 current present

于 2015-10-01T06:33:22.860 回答