如何在关闭一次后呈现相同的 modalView

发布于 2024-12-15 17:37:29 字数 633 浏览 1 评论 0原文

在第一次呈现模态视图控制器后,我在尝试呈现模态视图控制器时遇到了一些问题,所以我只是开始一个小测试方法,它以模态方式呈现、解除并再次呈现相同的控制器。

// This is just test Code.
MYViewController *vc = [[MYViewController alloc] init];
[self presentModalViewController:vc animated:YES];
[self dismissModalViewControllerAnimated:YES];
[self  presentModalViewController:vc animated:YES];

我收到错误:

2011-11-15 09:50:42.678 Proyecto3[1260:11603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <RootViewController: 0x6d9d090>.'

文档未在此处添加任何线索。

I'm having some problem trying to present a modal view controller after it has been presented the first time, so I just start a little test method, it presents, dismisses and presents again the same controller modally.

// This is just test Code.
MYViewController *vc = [[MYViewController alloc] init];
[self presentModalViewController:vc animated:YES];
[self dismissModalViewControllerAnimated:YES];
[self  presentModalViewController:vc animated:YES];

I get the error:

2011-11-15 09:50:42.678 Proyecto3[1260:11603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <RootViewController: 0x6d9d090>.'

The documentation does not add any clue here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

¢好甜 2024-12-22 17:37:29

@David,使 MYViewController 成为一个实例变量,并像这样初始化它:

if (myInstance==nil)
     //create instance of MYViewController
     //myInstance.delegate=self
//present modal VC

在 MYViewController 中创建一个协议来协调解雇 MYViewController 可能是在完成取消按钮上。在按钮操作中调用类似的东西

    done 
    {
       if([delegate respondsToSelector:@selector(willDismissModalView)])
       {
           [delegate willDismissModalView];
       }
   }

,并在 VC 的 willDismissModalView 方法中关闭 MYViewController。这样你就可以做n次了。

@David, make the MYViewController an instance variable, and initialize it like this:

if (myInstance==nil)
     //create instance of MYViewController
     //myInstance.delegate=self
//present modal VC

In MYViewController create a protocol to co-ordinate dismissing MYViewController may be on a done or cancel button. In the button action call some thing like

    done 
    {
       if([delegate respondsToSelector:@selector(willDismissModalView)])
       {
           [delegate willDismissModalView];
       }
   }

and in willDismissModalView method of your VC dismiss MYViewController. This way you can do it 'n' times.

神经大条 2024-12-22 17:37:29

在您的代码中 [selfmissModalViewControllerAnimated:YES];
不会对 modalViewController 执行任何操作,因为这里的“self”是您尝试呈现 modalViewController“vc”的 viewController。您再次呈现一个已经呈现的 modalViewController。这将导致终止。

您可以关闭该 viewController 中的 modalViewController vc,此处为 vc。

In your code [self dismissModalViewControllerAnimated:YES];
will do nothing to the modalViewController,since here the "self" is the viewController from where you are trying to present a modalViewController "vc".Again you are presenting a modalViewController which is already presented.this will result in a termination.

You can dismiss the modalViewController vc in that viewController,here vc.

私藏温柔 2024-12-22 17:37:29

您无法在动画时呈现/关闭视图控制器,我认为这可行

MYViewController *vc = [[MYViewController alloc] init];
[self presentModalViewController:vc animated:NO];
[self dismissModalViewControllerAnimated:NO];
[self  presentModalViewController:vc animated:YES];

但我真的没有看到这样做的任何理由,为什么您要关闭并重新呈现已经呈现的模态视图控制器?

You cannot present/dismiss the view controller while it is animated, I think this works

MYViewController *vc = [[MYViewController alloc] init];
[self presentModalViewController:vc animated:NO];
[self dismissModalViewControllerAnimated:NO];
[self  presentModalViewController:vc animated:YES];

But I don't really see any reason for doing it, why would you want to dismiss and re-present a modal view controller which is already presented?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文