首页 > 解决方案 > 如何在 Swift 5 中关闭第一个弹出框并显示第二个弹出框?

问题描述

我有3个屏幕。在第一个屏幕上,我有一个单击按钮,我正在显示一个弹出窗口。在那个弹出窗口中我有一个按钮,在那个按钮上单击我想打开另一个弹出窗口,但第一个弹出窗口应该被关闭?

有没有办法做到这一点?

我正在使用这种方式来显示弹出视图控制器

@IBAction func btnManualEntry(_ sender: Any) {

        if let vc = self.storyboard?.instantiateViewController(withIdentifier:"SummaryManualEditVC") {
            vc.modalTransitionStyle   = .crossDissolve;
            vc.modalPresentationStyle = .overCurrentContext
            self.present(vc, animated: true, completion: nil)

        }
    }

标签: iosswift

解决方案


只需引用presentingViewController,当您关闭第一个弹出框时,在关闭后打开另一个。

@IBAction func btnManualEntry(_ sender: Any) {

    if let presentingVC = self.presentingViewController {
        self.dismiss(animated: true) {
            if let vc = self.storyboard?.instantiateViewController(withIdentifier:"SummaryManualEditVC") {
                vc.modalTransitionStyle   = .crossDissolve;
                vc.modalPresentationStyle = .overCurrentContext
                presentingVC.present(vc, animated: true, completion: nil)

            }
        }
    }
}

推荐阅读