popViewController,然后立即显示一个警报控制器

时间:2020-02-21 02:20:38

标签: navigation uinavigationcontroller uialertcontroller popviewcontroller uialertviewcontroller

我正在尝试从警报操作中弹出控制器,然后转到另一个视图控制器。我想在进入另一个控制器后立即执行一些操作,比如说打开另一个警报控制器。我该怎么办?

UIAlertController.getAlertView("Success", message: "Your password has been successfully changed!", cancelButtonTitle: "Ok", cancelHandler: { (action) in
 self.navigationController?.popViewController(animated: true)
                        }).show(self)

1 个答案:

答案 0 :(得分:0)

如果您想在单击警报操作时返回上一个viewController,则下面的代码将为您提供帮助。

    let alert = UIAlertController(title: "Success", message: "Your password has been successfully changed!", preferredStyle: UIAlertController.Style.alert)
    alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.cancel, handler: { action in
        //perfoem any action you want on click of OK
                    self.navigationController?.popViewController(animated: true)
                }))
    self.present(alert, animated: true, completion: nil)