ViewDidDisappear not called when using presentViewController

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

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

where the collector is a UIImageViewPicker .

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

+7
source share
2 answers

This is the correct behavior. Here is an excerpt from viewWillDisappear: from the UIViewController API Documentation :

This method is called in response to a view that is removed from the view hierarchy. This method is called before the view is actually deleted and before any animations are configured.

Presenting a new view controller so that it hides another view controller is not taken into account, because an endangered view that is only actually removed from the view hierarchy (for example, with something like popViewControllerAnimated: .

+6
source

Thanks to iOS 13.

ViewWillDisappear , ViewDidDisappear , ViewWillAppear and ViewDidAppear will not be called on the view controller in iOS 13, which uses a new modal presentation that does not cover the entire screen.

Loans are collected at Arek Holko . He really saved my day.

enter image description here

0
source

Source: https://habr.com/ru/post/1400414/


All Articles