【发布时间】:2017-03-26 18:35:17
【问题描述】:
在一个简单的 ViewController 中,我添加了一个 UIButton。 我想使用“用户定义的运行时属性”。现在我添加了默认的 Bool 属性。
按钮是一个@IBOutlet:
@IBOutlet var button:UIButton!
故事板中的链接已完成。
我的应用中没有其他内容。
我收到了这个错误:
2017-03-26 20:31:44.935319+0200 ISAMG[357:47616] Failed to set (keyPath) user defined inspected property on (UIButton):
[<UIButton 0x15e3a780> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key keyPath.
我不明白我错过了什么。
编辑 1
按照@timaktimak 的建议,我创建了一个自定义 UIButton 类:
@IBDesignable
class ChoiceButton: UIButton {
@IBInspectable var keyPath: Bool! {
didSet {
print("didSet viewLabel, viewLabel = \(self.keyPath)")
}
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
}
}
错误是一样的:
2017-03-26 22:32:27.389126+0200 ISAMG[429:71565] Failed to set (keyPath) user defined inspected property on (ISAMG.ChoiceButton):
[<ISAMG.ChoiceButton 0x14e8f040> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key keyPath.
【问题讨论】:
标签: ios swift uibutton user-defined