UIAlertView导致应用程序崩溃

3

我正在尝试在我的Parse应用程序中创建一个UIAlertView,但是每次运行它时,它都会崩溃,并且我被带到ApplicationDelegate,那里我收到了一个SIGABRT。这是我的警报代码,我相信我没有做错任何事情,因为它之前曾经工作过...难道是因为我从Parse加载数据到表格视图中吗?

func displayAlert(title: String, message: String) {
    var alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)

    alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: { (action) ->    Void in


    }))

    presentViewController(alert, animated: true, completion: nil)
}

1
你的代码看起来没问题。你的崩溃是由其他地方引起的。 - Mundi
如果我移除警告,它就能正常工作。 - John Doe
这意味着崩溃的源头就在你调用 displayAlert 函数的附近。-- 还要检查 titlemessage 是否为 nil - Mundi
我尝试硬编码标题和消息,使它们始终是特定的消息,但仍然崩溃了。 - John Doe
1个回答

0

不确定您的问题是什么。您可以通过消除空闭包并在可能的情况下缩短参数来简化代码(Xcode 7b6)。但我认为这不是您的问题。相反,您应该展示调用此函数的代码。

var alert = UIAlertController(title: title, message: message, preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
presentViewController(alert, animated: true, completion: nil)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接