出现greenCircle图像,但是当我调用updateImage时出现错误
在解包可选值时意外发现nil
在这一行:
petImage.image = UIImage(named: "blackCircle")!
我添加了三个打印语句,试图弄清楚发生了什么,它们各自的输出如下所示。毋庸置疑,blackCircle图像永远不会出现。
class PetContainerVC: UIViewController {
@IBOutlet weak var petImage: UIImageView!
func updateImage() {
// print(UIImage(named: "blackCircle")) ---> Optional(<UIImage: 0x7fcea1c60320>, {57, 58})
// print(petImage) ---> fatal error: unexpectedly found nil while unwrapping an Optional value
// print(petImage.image) ---> fatal error: unexpectedly found nil while unwrapping an Optional value
petImage.image = UIImage(named: "blackCircle")! ---> fatal error: unexpectedly found nil while unwrapping an Optional value
}
override func viewDidLoad() {
petImage.image = UIImage(named: "greenCircle")!
super.viewDidLoad()
}
}