xcode 使用presentViewController时不调用viewDidDisappear
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9621346/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
viewDidDisappear not called when use presentViewController
提问by Kyle_at_QP
I have an UIViewControllerhaving this method:
我有UIViewController这个方法:
- (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];
}
In the second view controller (SendMsgViewController) viewDidLoadI have the following:
在第二个视图控制器 ( SendMsgViewController) 中,viewDidLoad我有以下内容:
[self presentViewController:picker animated:YES completion:NULL];
where picker is an UIImageViewPicker.
其中选择器是一个UIImageViewPicker.
The problem is, when I call the method openSendVCa new controller is opened, but viewWillDisappear(of the first viewController) is not called.
问题是,当我调用该方法时,openSendVC会打开一个新控制器,但未调用viewWillDisappear(第一个 viewController)。
采纳答案by yuji
That is the correct behavior. Here's an excerpt about viewWillDisappear:from the UIViewController API docs:
这是正确的行为。以下是关于摘录viewWillDisappear:从UIViewController的API文档:
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.
调用此方法是为了响应从视图层次结构中删除的视图。在实际删除视图之前和配置任何动画之前调用此方法。
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:).
呈现一个新的视图控制器以隐藏另一个视图控制器不算作视图消失——只有实际从视图层次结构中删除才算作(例如,使用类似popViewControllerAnimated:)。

