11

I have an UIViewController having this method:

- (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) viewDidLoad I have the following:

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

where picker is an UIImageViewPicker.

The problem is, when I call the method openSendVC a new controller is opened, but viewWillDisappear (of the first viewController) is not called.

Lorenzo B
  • 33,216
  • 24
  • 116
  • 190
Kyle_at_QP
  • 153
  • 1
  • 1
  • 7

1 Answers1

9

That is the correct behavior. Here's an excerpt about viewWillDisappear: from the 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.

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:).

yuji
  • 16,695
  • 4
  • 63
  • 64
  • 9
    But I'm observing that viewDidDisappear is called on the presenting view controller that is presenting a `UIModalPresentationFullScreen` modal, but not with `UIModalPresentationFormSheet` modal. – Hlung Aug 14 '17 at 08:07
  • 2
    @Hlung, you should post this comment as an answer! Thanks! – Borzh Feb 03 '20 at 18:58