并发UIAlertControllers

Fit*_*rst 15 uialertview ipad ios8 uialertcontroller

我正在将我的应用程序移植到iOS 8.0,并注意到UIAlertView已被弃用.

所以我改变了使用UIAlertController的东西.在大多数情况下都有效.

除了,当我的应用程序打开时,它会进行多次检查以向用户报告各种状态...

例如.."警告,你没有设置X并且在完成项目之前需要做Y"和"警告,你正在使用测试版并且不依赖于结果"等......(这些只是示例!)

在UIAlertView下,我会(比如说)同时获得两个警告框,用户必须点击两次才能解除两个...但它们都出现了.

在UIAlertController下面,使用下面的代码来显示"常规"警报,我只收到一条警报消息以及一条控制台消息:

警告:尝试在TestViewController上呈现UIAlertController:0x13f667bb0:0x13f63cb40已经呈现UIAlertController:0x13f54edf0

所以,虽然上面可能不是一个很好的例子,但我想有时可能需要在操作应用程序时因"事件"而提出多个全局警报.在旧的UIAlertView下,它们会出现,但似乎它们不会在UIAlertController下.

任何人都可以建议如何使用UIAlertController实现这一目标?

谢谢

+(void)presentAlert:(NSString*)alertMessage withTitle:(NSString*)title
{
    UIAlertController *alertView = [UIAlertController
                                    alertControllerWithTitle:title
                                    message:alertMessage
                                    preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction* ok = [UIAlertAction
                         actionWithTitle:kOkButtonTitle
                         style:UIAlertActionStyleDefault
                         handler:^(UIAlertAction * action)
                         {
                             //Do some thing here
                             [alertView dismissViewControllerAnimated:YES completion:nil];
                         }];

    [alertView addAction:ok];

    UIViewController *rootViewController = [[[UIApplication sharedApplication] delegate] window].rootViewController;
    [rootViewController presentViewController:alertView animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

编辑:我注意到在iOS8上,连续呈现两个AlertViews,它们"排队"并按顺序出现,而在iOS7中,它们同时出现.似乎Apple已经改变了UIAlertView来排队多个实例.是否有办法使用UIAlertController执行此操作而不继续使用(已弃用但已修改)UIAlertView ???

Rah*_*ade 5

在呈现 UIAlertController 时,我也面临一些问题。现在我可以建议的唯一解决方案是从最顶层的presentedViewContrller(如果有)或窗口的rootViewController 显示警报控制器。

UIViewController *presentingViewController = [[[UIApplication sharedApplication] delegate] window].rootViewController;

while(presentingViewController.presentedViewController != nil)
{
    presentingViewController = presentingViewController.presentedViewController;
}

[presentingViewController presentViewController:alertView animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

您收到的警告不仅限于 UIAlertController。视图控制器(在您的情况下是窗口的 rootViewController)一次只能显示一个视图控制器。