【发布时间】:2020-05-18 20:48:18
【问题描述】:
目前,我一直在关注 Coursera 课程,名为 Intro to Swift Programming 5。我关注的视频是关于 Xcode 的 MVC,我收到以下错误,即使我做了屏幕上的人所做的事情完成:
线程 1:异常:“[ setValue:forUndefinedKey:]:这个类不是键值 键 colorLabel 的编码兼容。”
我已经尝试查找它,但我看不到我会在哪里引用某些内容并将其删除。我还检查了主情节提要上我的任何参考插座附近是否有任何警告标志,但那里的一切似乎也都井井有条。
我的代码如下:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var modelLabel: UILabel!
@IBOutlet weak var colorLabel: UILabel!
@IBOutlet weak var priceLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
let appleProduct = AppleProduct(name: "iPhone X", color: "Space Gray", price: 999.99)
modelLabel.text = appleProduct.name
colorLabel.text = "in \(appleProduct.color)"
priceLabel.text = "$\(appleProduct.price)"
}
}
有没有其他人遇到过这个问题并且可以帮助我?我将不胜感激,如果不清楚,我很乐意提供所需的任何其他代码。谢谢!
【问题讨论】:
-
您没有在
ViewController的情节提要中正确设置类。目前是UIViewController。 -
我可以问一下它应该是什么吗?如果我尝试将 UIViewController 更改为 ViewController,它会给我更多错误,说它是从自身继承的。
-
不在您发布的代码中,在 InterfaceBuilder 中,在故事板中:stackoverflow.com/questions/33033129/…
-
我当前的 Storyboard 类是“Custom Pretty View”,它对应于我的视图文件 CustomPrettyView.swift。这不是应该的吗?