无需时间表以编程方式关闭UIAlertview

时间:2015-10-06 10:33:42

标签: ios swift uialertview

我在Swift项目中使用UIAlertView来显示执行的消息/当前操作,这是在网络事务发生时发生的。当我从API端点收到成功的响应时,我想关闭UIAlertView

有没有办法以编程方式关闭当前显示警报或不使用计时器。

2 个答案:

答案 0 :(得分:2)

在全局设置您的提醒名称,并在收到回复时添加以下行,这将使提醒消失

alert.dismissWithClickedButtonIndex(0, animated: true)

答案 1 :(得分:0)

以下是我对问题的回答

全局声明UIAlertview

   let alert : UIAlertView = UIAlertView()

在我开始网络转换之前的情况下,写下面的代码块:

  alert = UIAlertView(title: "MyAlert", message: "Message Body", delegate: self, cancelButtonTitle: nil, otherButtonTitles: nil,nil)
  alert.show()

获得成功回复后,关闭UIAlertView:

  alert.dismissWithClickedButtonIndex(0, animated: true)