Dismissing modal view controller results in a black screen

I had the black screen problem after presenting a screen with presentViewController: and dismissing it with dismissViewControllerAnimated:. My problem was that the dismiss command was unloading the entire view structure. My problem was resolved setting the modalPresentationStyle to UIModalPresentationOverFullScreen, as this:

viewController.modalPresentationStyle = UIModalPresentationOverFullScreen;
[self presentViewController:viewController animated:YES completion:nil];

I got the solution from here.


I found the solution - this answer really helped. The trick was in dismissing the view controller. It should be done like this:

[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];

and not like this:

[self dismissViewControllerAnimated:YES completion:nil];

Although the author of the linked answer suggests that a better approach would be to use delegation (presentED VC would define a protocol and presentING VC would subscribe to it and then dismiss the presentED VC once it asks for it), it wasn't feasible in my case.


Is this an iPad app? If yes, adding

modalVC.modalPresentationStyle = UIModalPresentationFullScreen

before

[self presentViewController:modalVC animated:YES completion:nil];

in MyViewController might do the trick.