ismissViewControllerAnimated在块中不

ismissViewControllerAnimated在块中不

本文介绍了dismissViewControllerAnimated在块中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在显示 UIAlertController 之后,我尝试关闭 UIViewController

I try to close a UIViewController after an UIAlertController has been shown.

这是我的代码:

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title
                                                                         message:msg
                                                                  preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Accept"
                                                   style:UIAlertActionStyleDefault
                                                 handler:^(UIAlertAction *action)
             {
                 [self dismissViewControllerAnimated:YES completion:nil];
             }];

[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:^{}];

然而, self 永远不会被解雇。有人知道如何解决这个问题吗?

However, self never gets dismissed. Anyone knows how to solve this?

更新

如果我设置 [self dismissViewControllerAnimated:YES completion:nil]; 在块之外,它可以工作。

if I set [self dismissViewControllerAnimated:YES completion:nil]; outside of the block, it works.

推荐答案

如果有人遇到同样的问题。我推了 UIViewController ,我没有用 presentViewController:animated:completion:来呈现它。这就是为什么应该使用 [self.navigationController popViewControllerAnimated:YES];

In case someone is having the same issue. I pushed the UIViewController, I didn't present it with presentViewController:animated:completion:. That's why [self.navigationController popViewControllerAnimated:YES]; should be used instead.

奇怪的是 [self dismissViewControllerAnimated:YES completion:nil]; 在街区之外工作并且没有在里面,我对此没有解释......

The strange thing is that [self dismissViewControllerAnimated:YES completion:nil]; worked outside of the block and didn't inside, I have no explanation for this...

这篇关于dismissViewControllerAnimated在块中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 03:30