Sotiris Kaniras
Sotiris Kaniras

Reputation: 680

Swift - Interactive dismiss of View Controller completion handler

In iOS 13 and above the default modal presentation style of a view controller allows you to dismiss it interactively. The thing is I need to know when a view controller is dismissed, to perform some actions.

Unfortunately, I cannot use viewWllDisappear and viewDidDisappear because there are other screens that are presented from that view controller, so those will be called as well.

Is there any way to handle an interactive dismiss of a View Controller?

EDIT; What I mean, is if there’s a way to handle this kind of dismiss. enter image description here

Upvotes: 0

Views: 541

Answers (1)

Rohit
Rohit

Reputation: 39

Your viewDidDisappear() will do the work for this as it will only be called for the viewController that you are dismissing.

You can try using the deinit() function as well.

You can also track this property on your viewController

var isMovingToParent: Bool

A Boolean value indicating whether the view controller is being moved to a parent view controller.

Or you can show your controller full screen while instantiating it.

For example,

 @objc fileprivate func continueButtonDidPress(){
   //TODO:- Go to Feed
    let viewController = MainViewController()
    viewController.modalTransitionStyle = .flipHorizontal
    viewController.modalPresentationStyle = .fullScreen
    present(viewController, animated: true, completion: nil)
}

Upvotes: 1

Related Questions