加载 XIB 此 class 不符合密钥的键值编码
Load XIB this class is not key value coding-compliant for the key
我刚刚创建了名称为 PopupViewForViewMoreDetail
的自定义 UIView
,我想在我的 ViewController 中添加此自定义视图,但每次获取低于错误
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<0x7f8155f2e430> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key mainView.'
如果我删除 mainView 的 IBOutlet 那么它将显示另一个变量的错误。
下面是我的代码
import UIKit
class PopupViewForViewMoreDetail: UIView {
@IBOutlet var darkBGView: UIView!
@IBOutlet var outerView: UIView!
@IBOutlet var mainView: UIView!
@IBOutlet var btnClose: UIButton!
override init(frame: CGRect) {
super.init(frame: frame)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}
我正在我的 viewController class 中添加此视图,如下所示。
let viewMoreDetailPopUp = Bundle.main.loadNibNamed("PopupViewForViewMoreDetail", owner: self, options: nil)?.first as! PopupViewForViewMoreDetail
self.view.addSubview(viewMoreDetailPopUp)
下面是我 IBOutlets
的截图
我也检查了下面的答案,但没有帮助我。
What does this mean? "'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X"
指导我的代码哪里出错了?
试试这个:
step 1:
let viewMoreDetailPopUp = UINib(nibName: "PopupViewForViewMoreDetail", bundle: nil).instantiate(withOwner: self, options: nil).first as! PopupViewForViewMoreDetail
step 2:
make sure you're setting class for the view instead of File's Owner
Step 3 :
Remove all outlets and re-outlet again
对我来说,我复制了一个 xib 来制作一个新的变体,但它没有选中从目标继承模块。
我刚刚创建了名称为 PopupViewForViewMoreDetail
的自定义 UIView
,我想在我的 ViewController 中添加此自定义视图,但每次获取低于错误
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<0x7f8155f2e430> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key mainView.'
如果我删除 mainView 的 IBOutlet 那么它将显示另一个变量的错误。
下面是我的代码
import UIKit
class PopupViewForViewMoreDetail: UIView {
@IBOutlet var darkBGView: UIView!
@IBOutlet var outerView: UIView!
@IBOutlet var mainView: UIView!
@IBOutlet var btnClose: UIButton!
override init(frame: CGRect) {
super.init(frame: frame)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}
我正在我的 viewController class 中添加此视图,如下所示。
let viewMoreDetailPopUp = Bundle.main.loadNibNamed("PopupViewForViewMoreDetail", owner: self, options: nil)?.first as! PopupViewForViewMoreDetail
self.view.addSubview(viewMoreDetailPopUp)
下面是我 IBOutlets
的截图我也检查了下面的答案,但没有帮助我。
What does this mean? "'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X"
指导我的代码哪里出错了?
试试这个:
step 1:
let viewMoreDetailPopUp = UINib(nibName: "PopupViewForViewMoreDetail", bundle: nil).instantiate(withOwner: self, options: nil).first as! PopupViewForViewMoreDetail
step 2: make sure you're setting class for the view instead of File's Owner
Step 3 : Remove all outlets and re-outlet again
对我来说,我复制了一个 xib 来制作一个新的变体,但它没有选中从目标继承模块。