首页 > 解决方案 > 单击按钮后如何限制警报解除?

问题描述

单击按钮后如何限制警报解除?

let alertController = UIAlertController(title: "Title", message: "Message", preferredStyle: .Alert)

// Create the actions
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default) {
    UIAlertAction in
    NSLog("OK Pressed")
}
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) {
    UIAlertAction in
    NSLog("Cancel Pressed")
}

// Add the actions
alertController.addAction(okAction)
alertController.addAction(cancelAction)

// Present the controller
self.presentViewController(alertController, animated: true, completion: nil)

即使我单击 okAction 按钮,是否有限制解除警报?

标签: iosswiftbuttonalert

解决方案


从您的代码中,我根据我的评论对此进行了测试:

let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default) {
    UIAlertAction in
      NSLog("OK Pressed")
      DispatchQueue.main.async { () -> Void in
        self.testAlert(sender)  // Or whatever functionalists that created the alertController
    }
}

推荐阅读