使用presentViewController时不调用viewDidDisappear [英] viewDidDisappear not called when use presentViewController
问题描述
我有一个 UIViewController
有这个方法:
I have an UIViewController
having this method:
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
NSLog(@"DISAPPEAR");
lastKnownOrientation = [self interfaceOrientation];
}
-(void)openSendVC{
SendMsgViewController *vc = [[SendMsgViewController alloc]initWithNibName:@"SendMsgViewController" bundle:nil];
[self.navigationController pushViewController:vc animated:NO];
}
在第二个视图控制器 (SendMsgViewController
) viewDidLoad
我有以下内容:
In the second view controller (SendMsgViewController
) viewDidLoad
I have the following:
[self presentViewController:picker animated:YES completion:NULL];
picker 是一个 UIImageViewPicker
.
where picker is an UIImageViewPicker
.
问题是,当我调用方法 openSendVC
时,会打开一个新控制器,但没有调用 viewWillDisappear
(第一个 viewController 的).
The problem is, when I call the method openSendVC
a new controller is opened, but viewWillDisappear
(of the first viewController) is not called.
推荐答案
这是正确的行为.以下是关于 viewWillDisappear:
的摘录,来自 UIViewController API 文档:
That is the correct behavior. Here's an excerpt about viewWillDisappear:
from the UIViewController API docs:
调用此方法是为了响应从视图层次结构中删除的视图.在实际移除视图和配置任何动画之前调用此方法.
This method is called in response to a view being removed from a view hierarchy. This method is called before the view is actually removed and before any animations are configured.
呈现一个新的视图控制器以隐藏另一个视图控制器不算作视图消失——实际上只有从视图层次结构中删除才算作(例如,使用类似 popViewControllerAnimated:
的东西).
Presenting a new view controller so that it hides the other view controller doesn't count as the view disappearing—only actually being removed from a view hierarchy does (e.g., with something like popViewControllerAnimated:
).
这篇关于使用presentViewController时不调用viewDidDisappear的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!