加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – 使用presentViewController时未调用viewDidDisappear

发布时间:2020-12-15 01:46:49 所属栏目:百科 来源:网络整理
导读:我有一个UIViewController有这个方法: - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; NSLog(@"DISAPPEAR"); lastKnownOrientation = [self interfaceOrientation];}-(void)openSendVC{ SendMsgViewController *vc = [[S
我有一个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我有以下内容:

[self presentViewController:picker animated:YES completion:NULL];

其中picker是UIImageViewPicker.

问题是,当我调用openSendVC方法时,会打开一个新的控制器,但是不会调用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.

呈现一个新的视图控制器以便它隐藏另一个视图控制器并不算作视图消失 – 实际上只是从视图层次结构中移除(例如,像popViewControllerAnimated :).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读