解雇由模态视图控制器呈现的UIAlertController [英] dismiss UIAlertController presented by a modal view controller

查看:128
本文介绍了解雇由模态视图控制器呈现的UIAlertController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎遇到了类似于尚未解决的问题中的问题: UIAlertController解雇他的presentViewController

I seem to be running into a problem similar to one in an unresolved posted question: UIAlertController dismissing his presentingViewController

我在普通的UIViewController上呈现模态视图控制器。然后我在该模态视图控制器上弹出警报。当我按ok关闭警报(使用下面的代码生成)时,模态视图控制器也被解除。

I am presenting a modal view controller on top of a normal UIViewController. Then I'm popping up an alert on that modal view controller. When I push "ok" to dismiss the alert (generated with the code below), the modal view controller is also dismissed.

UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK"
                                             style:UIAlertActionStyleDefault 
                                           handler:^(UIAlertAction *action{ 
                                                    [self dismissViewControllerAnimated: YES completion: nil];}];

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Sign up problem."
                                                               message:@"Some fields are empty. Please check your inputs and try again."
                                                        preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:ok];
[self presentViewController:alert animated:YES completion:nil];

如何解除警报?

我意识到我可以通过使用导航控制器类型设置而隐藏t来避免此问题他导航栏,所以我得到了与模态视图控制器相同的感觉,但这看起来很傻。谢谢。

I realize I can avoid this problem by using a navigation controller type setup instead and hiding the navigation bar, so I Get the same feel as the modal view controller, but this seems silly. Thanks.

推荐答案

不要在按钮处理程序中调用 self dismissViewController 。这特别声明您希望视图控制器被解除。

Don't call self dismissViewController in the button handler. That specifically states that you want the view controller dismissed.

您无需关闭警报。它会自动解散自己。您应该在按钮处理程序中执行的唯一操作是执行您需要的任何操作。如果您不需要做任何事情,请不要做任何事情。

You don't need to dismiss the alert. It will automatically dismiss itself. The only thing you should do in the button handler is perform whatever action you need. Do nothing if you don't need to do anything.

如果您的提醒只是一条消息,而您不需要执行任何操作,请执行以下操作:

If your alert is simply a message and you don't need to perform any action, just do this:

UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];

这篇关于解雇由模态视图控制器呈现的UIAlertController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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