并发 UIAlertControllers [英] Concurrent UIAlertControllers

查看:17
本文介绍了并发 UIAlertControllers的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm porting my app to iOS 8.0 and notice that UIAlertView is deprecated.

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

So I've changed things to use a UIAlertController. Which works in most circumstances.

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

Except, when my app opens, it does several checks to report various states back to the user...

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

E.g... "Warning, you haven't set X up and need to do Y before completing projects" and "Warning, you are using a beta version and do not rely on results" etc...(these are just examples!)

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

Under the UIAlertView, I would (say) get two alert boxes concurrently which the user has to tap twice to dismiss both...but they both appear.

在带有以下代码的 UIAlertController 下显示一般"警报,我只收到一条警报消息和一条控制台消息:

Under UIAlertController with the code below to present a 'general' alert, I only get one alert message along with a console message:

警告:尝试在 TestViewController 上显示 UIAlertController: 0x13f667bb0: 0x13f63cb40 已经显示 UIAlertController: 0x13f54edf0

Warning: Attempt to present UIAlertController: 0x13f667bb0 on TestViewController: 0x13f63cb40 which is already presenting UIAlertController: 0x13f54edf0

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

So, although the above probably isn't a good example, I'm thinking there may be times when more than one global alert may need to be presented due to 'events' whilst operating an app. Under the old UIAlertView, they would appear but it seems they will not under a UIAlertController.

谁能建议如何使用 UIAlertController 实现这一点?

Can anyone suggest how this could be achieved with a 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];

我注意到在 iOS8 上,连续呈现两个 AlertView,它们被排队"并顺序出现,而在 iOS7 中,它们同时出现.似乎 Apple 已更改 UIAlertView 以对多个实例进行排队.有没有办法用 UIAlertController 做到这一点,而无需继续使用(已弃用但已修改)的 UIAlertView???

I notice that on iOS8, presenting two AlertViews consecutively, they are 'queued' and appear sequentially whereas in iOS7, they appear concurrently. It seems Apple have altered UIAlertView to queue multiple instances. Is there a way to do this with UIAlertController without continuing to use the (deprecated but modified) UIAlertView???

推荐答案

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

I am also facing some problemls with UIAlertController when it comes to present it. Right now the only solution I can suggest is to present alert controller from top most presentedViewContrller if any or window's rootViewController.

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

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

[presentingViewController presentViewController:alertView animated:YES completion:nil];

您收到的警告不仅限于 UIAlertController.一个视图控制器(在你的例子中是窗口的 rootViewController)一次只能显示一个视图控制器.

The warning you are getting is not just limited to UIAlertController. A view controller(window's rootViewController in your case) can present only one view controller at a time.

这篇关于并发 UIAlertControllers的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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