gpt4 book ai didi

ios - 加载 XIB 此类与键的键值编码不兼容

转载 作者:可可西里 更新时间:2023-10-31 23:56:42 25 4
gpt4 key购买 nike

我刚刚创建了名为 PopupViewForViewMoreDetail 的自定义 UIView,我想在我的 ViewController 中添加这个自定义 View ,但每次都出现以下错误

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<0x7f8155f2e430> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key mainView.'

如果我删除 ma​​inViewIBOutlet 那么它将显示另一个变量的错误。

下面是我的代码

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)
}
}

我正在将这个 View 添加到我的 viewController 类中,如下所示。

 let viewMoreDetailPopUp =  Bundle.main.loadNibNamed("PopupViewForViewMoreDetail", owner: self, options: nil)?.first as! PopupViewForViewMoreDetail
self.view.addSubview(viewMoreDetailPopUp)

下面是我的IBOutlets

截图

enter image description here

我也检查了下面的答案,但没有帮助我。

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 Ownerenter image description here

enter image description here

Step 3 : Remove all outlets and re-outlet again

关于ios - 加载 XIB 此类与键的键值编码不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51056322/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com