【发布时间】:2012-01-17 04:12:02
【问题描述】:
全部
我有一个 NSTableView 以及一个 NSWindow 中显示的三个 NSTextField。 (在 IB 中)。 实体是这样设计的
Entity: Data
Attributes:
Title String
URL String
UserName String
Password String
我已经成功将NSArrayController绑定到managedObjectContext,将NSTableView绑定到arrayController的Title属性,NSTableView可以正确显示所有标题。
我要实现以下任务:
When user click one of the row in the NSTableView, the rest of the three NSTextFields can show the records of that row, respectively URL< username and password.
所以我对 URL 部分执行以下操作
将 NSTextField 绑定到 NSArrayController 的 selection.URL
运行程序时报错,但是如果我在绑定属性中取消选中“Raises for not applicable keys”,程序可以成功启动,并且值可以正确显示在文本中场地。谁能解释一下为什么?
错误提示:
[<NSTableView 0x102240d60> valueForUndefinedKey:]: this class is not key value coding-compliant for the key URL.
这是错误日志的一部分:
2012-01-17 11:52:57.533 Quills[98683:407] An uncaught exception was raised 2012-01-17 11:52:57.534 Quills[98683:407] [<NSTableView 0x102240d60> valueForUndefinedKey:]: this class is not key value coding-compliant for the key URL. 2012-01-17 11:52:57.540 Quills[98683:407] ( 0 CoreFoundation 0x00007fff8abd2286 __exceptionPreprocess + 198 1 libobjc.A.dylib 0x00007fff8d84cd5e objc_exception_throw + 43 2 CoreFoundation 0x00007fff8ac5c4c9 -[NSException raise] + 9 3 Foundation 0x00007fff8d1e8783 -[NSObject(NSKeyValueCoding) valueForUndefinedKey:]
+ 240 4 Foundation 0x00007fff8d11f462 _NSGetUsingKeyValueGetter + 108 5 Foundation 0x00007fff8d11f3e9 -[NSObject(NSKeyValueCoding) valueForKey:] + 392 6 Foundation 0x00007fff8d13ee76
-[NSObject(NSKeyValueCoding) valueForKeyPath:] + 348 7 AppKit 0x00007fff85ab33f1 -[NSArrayController
_multipleValueForKeyPath:atIndex:] + 84 8 AppKit 0x00007fff85ab24e5 -[NSArrayController _singleValueForKeyPath:] + 151 9 AppKit 0x00007fff8581909a
-[_NSControllerObjectProxy valueForKeyPath:] + 77 10 Foundation 0x00007fff8d13ee39 -[NSObject(NSKeyValueCoding) valueForKeyPath:] + 287 11 AppKit 0x00007fff85818f46
-[NSBinder _valueForKeyPath:ofObject:mode:raisesForNotApplicableKeys:] + 654 12 AppKit 0x00007fff85818c30 -[NSBinder valueForBinding:resolveMarkersToPlaceholders:] + 171 13 AppKit 0x00007fff85a1cc92 -[NSValueBinder
_referenceBindingValue] + 31 14 AppKit 0x00007fff85a1caa3 -[NSValueBinder
_adjustObject:mode:observedController:observedKeyPath:context:editableState:adjustState:]
+ 647 15 AppKit 0x00007fff85a1c788 -[NSValueBinder _observeValueForKeyPath:ofObject:context:] + 303 16 AppKit 0x00007fff85a345af
-[NSTextValueBinder _observeValueForKeyPath:ofObject:context:] + 43 17 AppKit 0x00007fff8580abdb
-[NSObject(NSKeyValueBindingCreation) bind:toObject:withKeyPath:options:] + 591
【问题讨论】:
-
确保您已将“URL”键绑定到数组控制器
-
嗨,香提,为什么?我的数组控制器绑定了managedObjectContext,NSTableView 绑定了arrayController 中的arrangeObject.title,并且URL 文本字段应该显示对应于NSTableView 中选定标题的URL。所以当我在 NSTableView 中选择一个标题时,“selection”应该是指这个数据,因此,selection.URL 应该指向 URL 属性,我有意义吗? (如果没有,我应该将此 URL 绑定到数组控制器的什么属性?-内容?)
-
@Sheldon 你说得很有道理。我遇到了完全相同的问题。
-
首先,不要将您的核心数据实体称为“数据”或“字符串”或其他任何名称。如果您确实想使用数据,请在其前面加上“Sheldon_Data”之类的前缀。 Core Data 在很大程度上依赖于字符串解析,它很容易混淆。其次,属性要小写,比如title、url、user_name等。
标签: macos cocoa core-data nsarraycontroller