gpt4 book ai didi

xcode - 无法绑定(bind)到 NSOutlineView 中的 NSButton 值

转载 作者:行者123 更新时间:2023-11-30 10:04:59 24 4
gpt4 key购买 nike

我有一个类(class),像这样:

class OTF:NSObject {
var name:String = ""
var nameID:Int? = 0
var identifier:Int = 0
var isOn:Int! = 1
var search:Int = 0
var selected:Bool! = false

init(name:String, nameID:Int?, identifier:Int) {
self.name = name
self.nameID = nameID
self.identifier = identifier

}}

class OTFeature:OTF {

var selDefault:Int?;
var parent:OTFType!

init (name:String, parent:OTFType, nameID:Int?, identifier:Int, selDefault:Int?) {
super.init(name: name, nameID: nameID, identifier: identifier)
self.selDefault = selDefault
self.parent = parent
}}

当我绑定(bind)(在 Interface Builder 中)NSOutlineView tableCellButton.objectValue.name 时对于放置在 NSTableCellView 内的 NSButton 的标题,我的按钮具有预期的标题:没关系。委托(delegate)和数据源运行良好。

但是如果我想绑定(bind)tableCellButton.ObjectValue.isOntableCellButton.objectValue.selected到 NSButton 值我收到错误:

[<OTFReview.OTFeature 0x6180000e2b80> valueForUndefinedKey:]: this class is not key value coding-compliant for the key selected.

最佳答案

您的“选定”属性是可选的,因此无法绑定(bind)。您需要将selected属性设为非可选并初始化。另外,您需要将选定属性指定为动态

尝试下面的代码,看看会发生什么。

class
ViewController: NSViewController {

dynamic var
selected : Bool = false

var
x : Bool = true

override func viewDidLoad() {
super.viewDidLoad()
bind( "x", toObject: self, withKeyPath: "selected", options: nil )
print( x )
}
@IBAction func
Do( _: AnyObject ) {
selected = !selected
print( x )
}
}

关于xcode - 无法绑定(bind)到 NSOutlineView 中的 NSButton 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36490718/

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