dismissViewControllerAnimated 在块内不起作用 [英] dismissViewControllerAnimated does not work within a block

查看:21
本文介绍了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 deniedViewControllerAnimated: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 deniedViewControllerAnimated: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 在块内不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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