Reputation: 6082
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 ?
Upvotes: 19
Views: 9983
Reputation: 1060
For me it was that I copied a xib to make a new variation and it unchecked inherit module from target.
Upvotes: 2
Reputation: 1662
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
Upvotes: 56