呈现ViewController,尽管UIAlertController位于视图Hierarchy

时间:2015-10-01 06:16:39

标签: ios swift apple-push-notifications uialertcontroller uiview-hierarchy

我希望presentViewController出现alertController

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

我开始知道UIAlertController出现在不同的主题上,所以想要在用户按下Ok Button后显示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>

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

我做错了什么?

1 个答案:

答案 0 :(得分:1)

创建UIAlertController时,将VCpresenting代码放在UIAlertAction中,如此

self.topErrorViewConstarints.constant = 108

self.view.updateConstraints()

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