0
votes

apple documentation on UIViewController dismiss(animated:completion:) says that

The presenting view controller is responsible for dismissing the view controller it presented. If you call this method on the presented view controller itself, UIKit asks the presenting view controller to handle the dismissal.

but when I override the presenting controller's dismiss

override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil)

it is not called

ViewController1 -> present ViewController2

ViewController2.dismiss -> dismiss from ViewController2 is called and ViewController1.(override)dismiss is not called

2
Did you manage to get override dismiss to fire in VC1? I'm facing the same issue. Any insight would help ;)Edouard Barbier
nope, I just used ViewController2.presentingViewController.dismissCiNN
Ok, thanks for letting me know ;)Edouard Barbier

2 Answers

1
votes

According to the documentation of present(_:animated:completion:):

The object on which you call this method may not always be the one that handles the presentation. Each presentation style has different rules governing its behavior. For example, a full-screen presentation must be made by a view controller that itself covers the entire screen. If the current view controller is unable to fulfill a request, it forwards the request up the view controller hierarchy to its nearest parent, which can then handle or forward the request.

In case of iPhone (horizontally compact environment) it uses FullScreen mode by default. So here ViewController1 may not be the 'presentingViewController'.

0
votes

[Spoiler - Work-around]

I had a similar issue with a modal vc and ended up working things out differently.

My modal style was initially:

 modalVC.modalPresentationStyle = .overCurrentContext

and changing that to

modalVC.modalPresentationStyle = .fullScreen

triggers the life cycle calls to fire on the presentingVC when I dismiss the modal so that did the trick for me. I can now make sure code runs whenever the modal gets dismissed without having to bother with delegation etc...

I hope that can help someone too in the future.