I wrote a custom view by xib in swift. The view shows correct and the @IBAction
is also right. But when I add an @IBOutlet
, the app will crash.
The error message is:
2016-03-15 22:32:16.650 ****[42692:1015001] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSObject 0x7f8ea483cd30> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key cancelBtn.'
And the xib:
And the code is:
class PYChangeNameView: UIView {
var confirmAction: ((name: String?) -> ())?
var cancelAction: (() -> ())?
@IBOutlet weak var cancelBtn: UIButton!
private init() {
super.init(frame: CGRectZero)
if let view = UIView.loadFromNibNamed("PYChangeNameView") {
view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
self.frame = UIScreen.mainScreen().bounds self.addSubview(view)
}
}
@IBAction func cancelClick(sender: AnyObject) {
PYCNVStaticValues.sharedInstance?.removeFromSuperview()
PYCNVStaticValues.cancelAction?()
}
}
The @IBAction
works, but the @IBOutlet
does not work.
}