解雇由模态视图控制器呈现的UIAlertController

编程入门 行业动态 更新时间:2024-10-27 19:27:18
本文介绍了解雇由模态视图控制器呈现的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

本文发布于:2023-11-27 19:31:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639316.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   控制器   模态   UIAlertController

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!