【发布时间】:2015-09-17 08:50:07
【问题描述】:
我正在学习 Swift 2 并将旧的 Objective-C 代码更改为 swift。
我只是在 nib 中放了一个 UILabel 并将其连接到 nib 的 Controller。
代码在模拟器(iOS 8.4 和 iOS 9)上运行,但在设备(iPhone 4s 和 iPhone 5s,均为 iOS 8.4)上崩溃,崩溃信息为:fatal error: unexpectedly found nil while unwrapping an Optional value。
相关代码如下:
我的视图控制器中的代码:
var round: Int = 0
@IBOutlet weak var nextRoundLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.nextRoundLabel.text = "\(self.round)"
}
}
viewController推送代码:
let rvc = RoundViewController()
rvc.modalTransitionStyle = UIModalTransitionStyle.PartialCurl
rvc.round = 1
self.navigationController?.pushViewController(rvc, animated: true)
发生错误的实例:
【问题讨论】:
-
在为设备构建之前尝试清理项目。或者尝试从设备中删除应用程序,然后从 Xcode 再次运行它。我过去曾遇到过故事板/笔尖未在设备上更新的问题。
-
@SteveWilford 我试过清理,但还是不行。
-
roundLabel != nextRoundLabel。请检查。
标签: ios uilabel swift2 fatal-error optional