【发布时间】:2018-03-21 10:14:52
【问题描述】:
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x101664480> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key label.'
当我像这样连接 IBOutlet 时为什么会出现此错误;@IBOutlet weak var label: UILabel!func viewDidLoad() {
super.viewDidLoad()
label.text = "Hello World!"
}
xib 文件的所有者设置为自定义 UIViewController 类
UIViewController + xib 有什么特别之处吗?
Connected IBOutlet
忽略import NightNight
Outlets
通过UITableView中的这个函数加载VC;func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let topicVCName = UIViewController(nibName: categories[indexPath.section].refName[indexPath.row], bundle: nil)
navigationController?.pushViewController(topicVCName, animated: true)
}
如果我拿走插座,xib 加载正常,没有错误。 (显然)
【问题讨论】:
-
你已经破坏了标签参考网点,在xib中查看
-
请使用inspector再检查
-
添加店铺图片
-
按⇧⌘F,输入
label,回车,查看搜索结果并修复问题。 -
这将我指向文件所有者的出口