我正在使用 xcode 8.2.1
致命错误:在展开可选值时意外发现 nil
这是代码,
class ShowMediaViewController: UIViewController {
var image: UIImage?
var titreText: String!
@IBOutlet var imageView: UIImageView!
//i tried @IBOutlet weak var imageView: UIImageView! but didn't work
@IBOutlet weak var titre: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
if image != nil {
//crashes here, because imageView is nil
imageView.image = image
} else {
print("image not found")
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
代码似乎在这一行崩溃
imageView.image = image
我认为是因为 imageView 为零?,因为我试过了
print(image)
结果很好,然后
print(imageView)
,它会导致致命错误但我确实初始化了它
@IBOutlet var imageView: UIImageView!
也许我的故事板有问题?
任何帮助将非常感激
**
更新 1 连接检查器
图 2 **