在同一窗口中弹出两个警报

时间:2015-10-19 12:45:19

标签: ios swift uialertcontroller

我试图在同一个窗口中收到两个弹出警报,

但是使用第二个警报功能,程序会运行但是当点击按钮时会崩溃并显示错误

错误: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)

}

2 个答案:

答案 0 :(得分:0)

您可以一次显示一个 UIAlertController

答案 1 :(得分:0)

您可以使用TKSwarmAlert自定义控件,但您不会有关闭按钮。