单击按钮后如何限制警报解除?
How to restrict alert to dismiss after button click?
如何限制单击按钮后关闭警报?
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 按钮,是否仍然可以限制关闭警报?
根据您的代码,我根据我的评论对此进行了测试:
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
}
}
如何限制单击按钮后关闭警报?
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 按钮,是否仍然可以限制关闭警报?
根据您的代码,我根据我的评论对此进行了测试:
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
}
}