present一个的ViewController虽然UIAlertController在视图层次 [英] Present a ViewController although UIAlertController is in the view Hierarchy

查看:2406
本文介绍了present一个的ViewController虽然UIAlertController在视图层次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想 presentViewController alertController 是presented。

我想,如用户是否$ P $现在psses确定按钮,我想显示的ViewController 从AppDelegate中的PushNotification。

我才知道,这样 UIAlertController 是psented在不同的线程$ P $所以想present的的ViewController 后用户presses OK按钮,移动到主线程如下:

  FUNC presentRScreenFromRootViewController()
{    让故事板:UIStoryboard = UIStoryboard(名称:主,捆绑:无)
    让rViewController = storyboard.instantiateViewControllerWithIdentifier(RSH)作为! R_SVC
    dispatch_async(dispatch_get_main_queue(),{        self.window .rootViewController presentViewController?(rViewController,动画:真的,完成:无)
    });}

但我得到的警告:


 尝试present< BB.R_SVC:0x15b983600>上
 < SWRevealViewController:0x15652df00>这已经是presenting
 < UIAlertController:0x15b4f2dd0>


这是因为的ViewController是presenting alertcontroller.Other倍,其工作well..My RootViewController的变化并移动至下一screen..But当有UIAlertController我得到警告的企图present的ViewController这是不是在视图层次

我究竟做错了什么?


解决方案

创建UIAlertController时,请将您VC presenting code在像这样的一个UIAlertAction

 让警报= UIAlertController(标题:你的标题,邮件移动到下一个VC?,preferredStyle:UIAlertController:UIAlertControllerStyle.Alert)
让我们行动:UIAlertAction = UIAlertAction(标题:是移动到下一个VC,风格:UIAlertActionStyle.Default){行动 - >在无效
    让rViewController = storyboard.instantiateViewControllerWithIdentifier(RSH)作为! R_SVC
    。自presentViewController(rViewController,动画:真实,完整度:无)})
alert.addAction(DEFAULTACTION)。自presentViewController(警报,动画:真的,完成:无)

编辑:也许尝试<一个href=\"http://stackoverflow.com/questions/28636640/dismiss-all-uialertcontrollers-currently-$p$psented?rq=1\">Dismiss所有UIAlertControllers目前presented 。

I want to presentViewController when an alertController is presented.

I want such as if user presses the Ok button now i want to show the ViewController from AppDelegate on PushNotification.

I came to know on SO that UIAlertController is presented on different thread so want to present the ViewController after user presses Ok Button and moves on to main thread as below:

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)


    });

}

But I get warning as:

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

This is because the viewcontroller is presenting alertcontroller.Other times its working well..My rootViewController changes and moves to next screen..But when there is UIAlertController i get warning as attempt to present viewcontroller which is not in the view hierarchy

What am i doing wrong?

解决方案

when creating UIAlertController, place you VCpresenting code in the an UIAlertAction like so

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)

edit: Maybe try Dismiss all UIAlertControllers currently presented.

这篇关于present一个的ViewController虽然UIAlertController在视图层次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆