如何在关闭一次后呈现相同的 modalView
在第一次呈现模态视图控制器后,我在尝试呈现模态视图控制器时遇到了一些问题,所以我只是开始一个小测试方法,它以模态方式呈现、解除并再次呈现相同的控制器。
// 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
@David,使 MYViewController 成为一个实例变量,并像这样初始化它:
在 MYViewController 中创建一个协议来协调解雇 MYViewController 可能是在
完成
或取消
按钮上。在按钮操作中调用类似的东西,并在 VC 的
willDismissModalView
方法中关闭MYViewController
。这样你就可以做n次了。@David, make the
MYViewController
an instance variable, and initialize it like this:In
MYViewController
create a protocol to co-ordinate dismissingMYViewController
may be on adone
orcancel
button. In the button action call some thing likeand in
willDismissModalView
method of your VC dismissMYViewController
. This way you can do it 'n' times.在您的代码中 [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.
您无法在动画时呈现/关闭视图控制器,我认为这可行
但我真的没有看到这样做的任何理由,为什么您要关闭并重新呈现已经呈现的模态视图控制器?
You cannot present/dismiss the view controller while it is animated, I think this works
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?