ios - 使用 presentViewController 时未调用 viewDidDisappear

标签 ios xcode uiviewcontroller viewwillappear

我有一个 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/

相关文章:

ios - 使用 stackview 时偏离中心 center.x

ios - 在代码中更改大小分类约束的常量,但它恢复为 Storyboard 值

objective-c - LLDB 等同于 Xcode4.1 中 GDB 中的 `po`?

ios - 如何使用 Swift 将通知数据传递给 View Controller

ios - self.parentViewController 记录 UINavigationController,但表现得像 UIViewController

ios - objective-c 清除 NSURLCredential - NSURLCredentialPersistenceForSession

ios - 覆盖数组swift ios中的旧对象

ios - 从 ScrollView 中的 UIimageView 获取可见部分图像

swift - 更改 DatePicker 的字体

ios - UIViewController 最佳实践——加载