ios - 按下按钮时关闭警报 Swift

标签 ios swift uialertcontroller

我有使用此代码的警报 View :

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。

关于ios - 按下按钮时关闭警报 Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45575012/

相关文章:

ios - View 内发现未知约束

ios - 如何刷新 UITableViewCell 中的 UIImage?

objective-c - Swift 无法将 CBPeripheral 类型的值转换为预期的参数类型

ios - UIAlertController 在调用 `presentViewController:` 时移动到屏幕顶部的错误位置

ios - 如何通过在 Swift 中的 UIAlertController 警报中按下按钮,使用 NSXMLParser 和提要地址上的变量来解析 RSS 提要?

ios - 如何将 Tableview 固定到屏幕上

ios - 可以使用 'private' NSNotification 名称吗?

ios - Alamofire 5.0+ MultipartFormData 上传不记名 token

ios - uiwebview 忽略样式标签

ios - 是否可以在 UIAlertController 内的一行中插入两个文本字段