Ios 按下按钮时关闭警报

Ios 按下按钮时关闭警报,ios,swift,uialertcontroller,Ios,Swift,Uialertcontroller,我使用以下代码创建了警报视图: func alert() { let alert = UIAlertController(title: "Time Is Up", message: "Either your company has Sold or had to Fold! (Click the button below to see)", preferr

我使用以下代码创建了警报视图:

func alert() {
    let alert = UIAlertController(title: "Time Is Up",
                                  message: "Either your company has Sold or had to Fold! (Click the button below to see)",
                                  preferredStyle: .alert)
    let action = UIAlertAction(title: "Next", style: .default) { _ in
        self.performSegue(withIdentifier: "congratsSegue", sender: nil)
    }

    alert.addAction(action)

    self.present(alert, animated: true, completion: nil)
}
然后,我想在按下“完成”按钮时关闭此警报:

@IBAction func donePressed() {
}
这可以在Swift中实现吗

self.dismiss(animated: true, completion: nil)

我想你不会想那样做,但我想你可以
self
这是viewController。

您还可以在UIAlert上添加两个操作按钮,一个用于下一步,另一个用于取消。您不能在单击按钮时解除警报,因为当view controller上出现警报时,您无权访问view controller。最好的选择是您需要再设置一个操作,如“取消”,单击后您可以解除警报警报。实际上这不起作用。是的@Donal我会这么做,但这是一个测验,所以一旦时间到了,我希望他们去下一个控制器。有什么解决方法吗?只需使用自己的隐藏和显示方法创建自己的演示UI即可。这应该很容易,而且我相信GitHub上有很多库。@Josh你们的意思是当测验时间到了,警报应该自动关闭并转到下一个控制器,或者你们需要在按钮上设置ant操作。