How to programmatically dismiss UIAlertController without any buttons?

前端 未结 5 1544
[愿得一人]
[愿得一人] 2020-12-09 07:52

I\'m presenting an UIAlertViewController without any buttons, as it is supposed to just inform users that uploading is in progress. The app is supposed to upload some files

5条回答
  •  没有蜡笔的小新
    2020-12-09 08:21

    If you want to post an alert that displays briefly, then dismisses itself, you could use the following method:

      func postAlert(title: String, message: String) {
        let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
        self.present(alert, animated: true, completion: nil)
    
        // delays execution of code to dismiss
        DispatchQueue.main.asyncAfter(deadline: .now() + 2.0, execute: {
          alert.dismiss(animated: true, completion: nil)
        })
      }
    

提交回复
热议问题