模态视图控制器不调用呈现视图控制器的dismissModalViewControllerAnimated:方法
在我的模态视图控制器中,我有一个按钮处理方法,其中包括
[self dismissModalViewControllerAnimated: YES];
在呈现视图控制器中,我重写dismissModalViewControllerAnimated:如下:
-(void) dismissModalViewControllerAnimated: (BOOL)animated
{
NSLog(@"dismiss");
[super dismissModalViewControllerAnimated: animated];
}
当触摸按钮时,按钮处理方法被调用,但dismissModalViewControllerAnimated:重写似乎没有被调用: NSLog(@"解雇");语句不会被调用,并且方法内的断点不会被命中。
我尝试过
[[self presentingViewController] dismissModalViewControllerAnimated: YES];
,但这也不起作用。然而,模态视图控制器确实被忽略了。
知道可能出了什么问题吗?
In my modal view controller I have a button handling method that includes
[self dismissModalViewControllerAnimated: YES];
In the presenting view controller I override dismissModalViewControllerAnimated: as follows:
-(void) dismissModalViewControllerAnimated: (BOOL)animated
{
NSLog(@"dismiss");
[super dismissModalViewControllerAnimated: animated];
}
When the button is touched, the button handling method gets called, but the dismissModalViewControllerAnimated: override does not seem to get called: the NSLog(@"dismiss"); statement isn't called, and a breakpoint inside the method doesn't get hit.
I tried
[[self presentingViewController] dismissModalViewControllerAnimated: YES];
but that didn't work either. However, the modal view controller does get dismissed.
Any idea what might be going wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这通常是通过将呈现视图控制器声明为模式视图控制器的委托来处理的。然后,模态 VC 在呈现的 VC 中调用委托方法来消除它创建的模态转换。
示例:
Modal VC.h:
Modal VC.m:
呈现 VC.h:
呈现 VC.m:
This is normally handled by declaring your presenting view controller as a delegate for your modal view controller. The modal VC then called a delegate method in the presenting VC to dismiss the modal transition it created.
Example:
Modal VC.h:
Modal VC.m:
Presenting VC.h:
Presenting VC.m:
来自 iOS 6 编程,作者:Matt Neuburg:
TL;博士
1. 在所需的
presentingViewController
上将definesPresentationContext
设置为 true2. 在所需的
presentedViewController
上将modalPresentationStyle
设置为UIModalPresentationCurrentContext
from Programming iOS 6, by Matt Neuburg:
TL;DR
1. set
definesPresentationContext
to true on the desiredpresentingViewController
2. set
modalPresentationStyle
toUIModalPresentationCurrentContext
on the desiredpresentedViewController
呈现模态视图控制器的代码包含在 UIViewController 中,而 UIViewController 又包含在 UINavigationController 中。当我打电话
或
解雇消息被发送到 UINavigationController 对象时。
The code that presented the modal view controller was contained in a UIViewController, which was in turn contained in a UINavigationController. When I called
or
the dismissal message was being sent to the UINavigationController object.