在视图控制器中获得被解雇的PopupDialog的通知

时间:2018-05-09 14:25:40

标签: ios swift

我有一个项目正在使用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内,PopupDialog可能会被self.dismiss(animated: true)

解雇

这很有效但是我不确定启动视图控制器(运行self.present的位置)如何通知PopupDialog已被解除。

我试过了

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

    }

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

2 个答案:

答案 0 :(得分:3)

您可以像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
...

答案 1 :(得分:1)

根据您正在使用的PopupDialog的文档,弹出窗口的按钮具有完成块,您可以在其中捕获对话框是否将被解除。

或者您现在最简单的方法是在PopupDialog实例化中添加完成块。

像这样:

来自:

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

要:

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

请告诉我这是否有帮助!