加载XIB此类不符合密钥的密钥值编码要求 [英] Load XIB this class is not key value coding-compliant for the key
问题描述
我只创建了名称为 PopupViewForViewMoreDetail
的自定义 UIView
,我想在我的中添加此自定义视图ViewController ,但每次低于错误
由于未捕获的异常 NSUnknownKeyException而终止应用程序,原因: [< 0x7f8155f2e430 > setValue:forUndefinedKey:]:此类不兼容键mainView的键值编码。'
如果我删除 mainView 的> IBOutlet ,则另一个变量将显示错误。
下面是我的代码
导入UIKit
类PopupViewForViewMoreDetail:UIView {
@IBOutlet var darkBGView:UIView!
@IBOutlet var externalView:UIView!
@IBOutlet var mainView:UIView!
@IBOutlet var btnClose:UIButton!
覆盖init(frame:CGRect){
super.init(frame:frame)
}
是否需要init?(编码器aDecoder:NSCoder) {
super.init(coder:aDecoder)
}
}
,然后将此视图添加到我的viewController类中,如下所示。
让viewMoreDetailPopUp = Bundle.main.loadNibNamed( PopupViewForViewMoreDetail,所有者:自我,选项:无)? PopupViewForViewMoreDetail
self.view.addSubview(viewMoreDetailPopUp)
下面是我的屏幕截图IBOutlets
我也在下面进行了检查答案,但没有帮助我。
第3步:
删除所有网点,然后再次重新出口
I just create custom UIView
with name PopupViewForViewMoreDetail
and I want to add this custom view in my ViewController but each time getting below error
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<0x7f8155f2e430> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key mainView.'
if I remove IBOutlet of mainView then It will be display error for another variable.
Below is my code
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)
}
}
and I'm adding this view in my viewController class like below.
let viewMoreDetailPopUp = Bundle.main.loadNibNamed("PopupViewForViewMoreDetail", owner: self, options: nil)?.first as! PopupViewForViewMoreDetail
self.view.addSubview(viewMoreDetailPopUp)
Below is my screenshot for IBOutlets
I also checked below answer but didn't help me.
Guide me where I'm going wrong in my code ?
try this :
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此类不符合密钥的密钥值编码要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!