问题描述
我有一个 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];
}
在第二个视图控制器中( SendMsgViewController
) viewDidLoad
我有以下内容:
In the second view controller (SendMsgViewController
) viewDidLoad
I have the following:
[self presentViewController:picker animated:YES completion:NULL];
其中选择器是 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.
推荐答案
这是正确的行为。以下是来自:
That is the correct behavior. Here's an excerpt about viewWillDisappear:
from the UIViewController API docs:
呈现新的视图控制器以使其隐藏其他视图控制器不计入视图消失 - 实际上只从视图层次结构中删除(例如,使用类似 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!