-2
我試圖讓兩人在同一個窗口彈出警報,兩個彈出警報在同一窗口
但第二警報功能,程序運行,但是當點擊該按鈕時,錯誤
崩潰錯誤:的libC++ abi.dylib:與類型的未捕獲的異常NSException
@IBAction func buttonPressed(sender: UIButton) {
let title = "Display Title"
let message = "You just clicked on Display Alert"
let okText = "OK"
let title1 = "Display Title"
let message1 = "You just clicked on Display Alert"
let okText1 = "OK"
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
let okayButton = UIAlertAction(title: okText, style: UIAlertActionStyle.Cancel, handler: nil)
alert.addAction(okayButton)
let alert1 = UIAlertController(title: "title1", message: "message1", preferredStyle: UIAlertControllerStyle.Alert)
let okayButton1 = UIAlertAction(title: okText1, style: UIAlertActionStyle.Cancel, handler: nil)
alert.addAction(okayButton1)
presentViewController(alert, animated: true, completion: nil)
presentViewController(alert1, animated: true, completion: nil)
}
您使用'「title1」'和'「message1」'作爲字符串文字而不是變量,並且您將'okayButton1'添加到'alert'而不是'alert1'。這是故意的嗎? – Arc676
我糾正了我的錯誤,現在程序沒有崩潰...但沒有第二個彈出警報..每次只出現第一個警報 – Maan
只是出於好奇,爲什麼你必須聲明相同的3個字符串兩次? – Arc676