【问题标题】:UIAlertView Crashes AppUIAlertView 崩溃应用
【发布时间】:2015-09-09 17:54:03
【问题描述】:

我试图在我的 Parse 应用程序上创建一个 UIAlertView,但由于某种原因,每次我运行它时,它都会崩溃,我被带到 ApplicationDelegate,在那里我得到了一个 SIGABRT。这是我的警报代码,我很确定我没有做错任何事情,因为它以前工作过……是因为我正在从 Parse 将数据加载到 tableview 中吗?

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)
}

【问题讨论】:

  • 您的代码看起来不错。您的崩溃是由其他地方引起的。
  • 如果我删除警报,它确实有效。
  • 这意味着崩溃的源头在您调用displayAlert 函数的位置附近。 -- 还要检查titlemessage 是否为nil
  • 我试图硬设置标题和消息,以便它们始终是特定的消息并且它仍然崩溃。

标签: ios xcode swift uialertview


【解决方案1】:

不确定您的问题是什么。您可以通过消除空闭包并尽可能缩短参数来简化代码如下(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)

【讨论】:

    猜你喜欢
    • 2012-11-19
    • 1970-01-01
    • 2015-04-07
    • 1970-01-01
    • 2015-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多