我需要一個UIAlert的幫助。我收到一個錯誤"UIAlertController can only have one action with a style of UIAlertActionStyleCancel"
。我知道這是因爲我在該功能之外啓動了此警報,但不確定如何解決該警報。如何在if條件下訪問警報?以編程方式取消警報Swift
let alertView = UIAlertController(title: "Blah", message: "", preferredStyle: UIAlertControllerStyle.Alert)
@IBAction func blahButtonPressed(sender: AnyObject) {
alertView.addAction(UIAlertAction(title: "Do Something", style: .Default, handler: { (action: UIAlertAction!) in
// I have code here
}))
alertView.addAction(UIAlertAction(title: "Do Something 2", style: .Default, handler: { (action: UIAlertAction!) in
// I have code here
}))
alertView.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: { (action: UIAlertAction!) in
// I have code here
}))
presentViewController(alertView, animated: true, completion: nil)
}
代碼後來我通過藍牙獲取值,需要解除警報,如果值低於80
if blah < 80 {
alertView.dismissViewControllerAnimated(true, completion: nil)
}
blahButtonPressed被執行了多次?錯誤消息聽起來像你添加「取消」多次。 –
不,只是一個按鈕。我只按一次,而不是在其他地方打電話。 – KotaBear233