我有一个 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];
}
在第二个 View Controller (SendMsgViewController
) viewDidLoad
我有以下内容:
[self presentViewController:picker animated:YES completion:NULL];
其中 picker 是一个 UIImageViewPicker
。
问题是,当我调用方法 openSendVC
时,一个新的 Controller 被打开,但是 viewWillDisappear
(第一个 viewController 的)没有被调用。
最佳答案
这是正确的行为。这是关于 viewWillDisappear:
的摘录,来自 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.
呈现一个新的 View Controller 以使其隐藏另一个 View Controller 并不算作 View 消失——只有实际从 View 层次结构中移除才算作 View 消失(例如,使用类似 popViewControllerAnimated:
的东西) .
关于ios - 使用 presentViewController 时未调用 viewDidDisappear,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9621346/