0

I have a project that is making use of https://github.com/Orderella/PopupDialog for popup dialogs which works very well.

A dialog is created an presenting like:

let ratingVC = PopupViewController(nibName: "PopupViewController", bundle: nil)
        ratingVC.apiKey = self.apiKey
        ratingVC.accountNumberString = accountNumberString        

        let popup = PopupDialog(viewController: ratingVC, buttonAlignment: .horizontal, transitionStyle: .bounceDown, gestureDismissal: true)
        ratingVC.presentedPopup = popup
self.present(popup, animated: true, completion: nil)

Which allows for custom view controller work within the popup. Within the PopupViewController the PopupDialog might get dismissed using self.dismiss(animated: true)

This works well however I'm not sure how the launching view controller (where self.present is run) would get notified that the PopupDialog has been dismissed.

I have tried

override func dismiss(animated flag: Bool, completion: (() -> Void)?)
    {
        super.dismiss(animated: flag, completion:completion)

    }

In the launching view controller but this doesn't get called.

DevWithZachary
  • 3,545
  • 11
  • 49
  • 101
  • maybe firing a notification or creating a delegate inside dismiss `self.dismiss(animated: true) {//fire notification or set delegate}` – GIJOW May 09 '18 at 14:38

2 Answers2

3

You could create a PopupViewControllerDelegate like the one described in this SO answer, something like this.

protocol PopupViewControllerDelegate:class {
    func viewControllerDidDismiss(_ sender: PopupViewController)
}

class PopupViewController: UIViewController {
     ...
     weak var delegate: PopupViewControllerDelegate?
     ...
}

and call it when the ViewController is dismissed.

Then implement PopupViewControllerDelegate protocol in the launching view controller and set it when the PopupViewController is created:

let ratingVC = PopupViewController(nibName: "PopupViewController", bundle: nil)
ratingVC.delegate = self
...
LorenzOliveto
  • 7,796
  • 1
  • 20
  • 47
1

Based on the docs of the PopupDialog you're using, the buttons of the popup have completion blocks, in which you can catch if the dialog is going to be dismissed or not.

OR the easiest way you can do right now is to add the completion block in your PopupDialog instantiation.

Like so:

From:

let popup = PopupDialog(viewController: ratingVC, buttonAlignment: .horizontal, transitionStyle: .bounceDown, gestureDismissal: true)

To:

let popup = PopupDialog(viewController: ratingVC, buttonAlignment: .horizontal, transitionStyle: .bounceDown, gestureDismissal: true) {
    print("PopupDialog has been dismissed! ✅")
}

Let me know if this helps!

Glenn Posadas
  • 12,555
  • 6
  • 54
  • 95