我有一个项目正在利用https://github.com/Orderella/PopupDialog弹出对话框,这是非常好的工作。
将创建一个演示对话框,如下所示:

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)

允许自定义视图控制器在弹出窗口中工作。在PopupViewController中,使用self.dismiss(animated: true)可能会取消弹出对话框
这工作得很好,但是我不确定如何通知启动视图控制器(self.present在其中运行)弹出对话框已被关闭。
我试过了
override func dismiss(animated flag: Bool, completion: (() -> Void)?)
    {
        super.dismiss(animated: flag, completion:completion)

    }

在启动视图控制器中,但这不会被调用。

最佳答案

您可以创建一个类似于this SO answer中描述的PopupViewControllerDelegate,如下所示。

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

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

当ViewController被解除时调用它。
然后在启动视图控制器中实现PopupViewControllerDelegate协议,并在创建PopupViewController时进行设置:
let ratingVC = PopupViewController(nibName: "PopupViewController", bundle: nil)
ratingVC.delegate = self
...

08-05 15:56