【发布时间】:2015-09-20 17:18:17
【问题描述】:
当我尝试在 Swift 中设置 UILabel 时,应用程序崩溃并且我收到一条错误消息:“致命错误:在展开可选值时意外发现 nil”这是我的代码,当我设置框架时它崩溃了。
var newsFeed1: UILabel!
let Description = object!["Description"] as! String
newsFeed1.frame = CGRect(x: 22.5, y: 315, width: 475, height: 50)
newsFeed1.text = Description
storeTab.addSubview(newsFeed1)
【问题讨论】:
-
你在哪里给
newsFeed1赋值?你错过了newsFeed1 = UILabel()这行! -
还要检查
object不是nil -
@luk2302 谢谢我刚刚注意到我忘记了