cocoa - 取消选择绑定(bind) NSTableview 列内的复选框时出现问题

标签 cocoa nstableview osx-mavericks cocoa-bindings nsbuttoncell

我正在使用this project ,创建者 aneesh171显示了 NSTableView 中复选框的创建以及如何绑定(bind)它们。我是 OSX 开发新手,并试图了解它是如何工作的。

该项目基本上是绑定(bind)到数组 Controller 的 NSTableView 列内的复选框。

由于某种原因,当我取消选择其中一个复选框时,控制台窗口上会显示以下消息:

2014-04-03 04:22:55.579 MyApp[5735:303] Error setting value for key path objectValue.selected of object <NSAutounbinder: 0x600000258120 - a nonretaining proxy for <NSTableCellView: 0x60000019f890>> (from bound object <NSButton: 0x60000015efb0>): [<__NSDictionaryI 0x61000006f540> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key selected.
2014-04-03 04:22:55.581 MyApp[5735:303] (
    0   CoreFoundation                      0x00007fff87b3a25c __exceptionPreprocess + 172
    1   libobjc.A.dylib                     0x00007fff8a3f6e75 objc_exception_throw + 43
    2   CoreFoundation                      0x00007fff87b3a038 +[NSException raise:format:arguments:] + 104
    3   AppKit                              0x00007fff927936c5 -[NSBinder _setValue:forKeyPath:ofObject:mode:validateImmediately:raisesForNotApplicableKeys:error:] + 837
    4   AppKit                              0x00007fff92793327 -[NSBinder setValue:forBinding:error:] + 245
    5   AppKit                              0x00007fff92c8b4ee -[NSValueBinder _applyObjectValue:forBinding:canRecoverFromErrors:handleErrors:typeOfAlert:discardEditingCallback:otherCallback:callbackContextInfo:didRunAlert:] + 194
    6   AppKit                              0x00007fff92c8b871 -[NSValueBinder applyDisplayedValueHandleErrors:typeOfAlert:canRecoverFromErrors:discardEditingCallback:otherCallback:callbackContextInfo:didRunAlert:error:] + 621
    7   AppKit                              0x00007fff927c5107 -[NSValueBinder performAction:] + 288
    8   AppKit                              0x00007fff927c4fc5 -[_NSBindingAdaptor _objectDidTriggerAction:bindingAdaptor:] + 133
    9   AppKit                              0x00007fff927531a0 -[NSControl sendAction:to:] + 56
    10  AppKit                              0x00007fff9279fced -[NSCell _sendActionFrom:] + 128
    11  AppKit                              0x00007fff927b96c5 -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2316
    12  AppKit                              0x00007fff927b8a97 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 487
    13  AppKit                              0x00007fff927b81ad -[NSControl mouseDown:] + 706
    14  AppKit                              0x00007fff92739b48 -[NSWindow sendEvent:] + 11296
    15  AppKit                              0x00007fff926d86e4 -[NSApplication sendEvent:] + 2021
    16  AppKit                              0x00007fff92528b89 -[NSApplication run] + 646
    17  AppKit                              0x00007fff92513913 NSApplicationMain + 940
    18  MyApp                               0x0000000100049132 main + 34
    19  libdyld.dylib                       0x00007fff85ffe5fd start + 1

选中该复选框后,此消息不会显示在控制台上。

你们能告诉我出了什么问题吗?

最佳答案

我更新了项目的 git 版本。

每当您通过值绑定(bind)绑定(bind)控件时,它都会调用其 getter 方法来加载值。而当你尝试修改这些值时,它会尝试调用属性的setter方法。在项目中,字典是硬编码的,因此没有 setter 方法,这就是为什么您收到“关键路径 objectValue.selected 的错误设置值”的原因。

检查已创建 FruitModel 的新版本,该版本解决了 setter 问题。

如果您遇到任何问题,请告诉我。

关于cocoa - 取消选择绑定(bind) NSTableview 列内的复选框时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22827414/

相关文章:

objective-c - 使用 Cocoa 减少图像字节大小

iphone - 如何知道两个 NSDate 是否在同一天

macos - 多个 NSTableViews 选择

objective-c - 在 Objective-C 中向 NSTableView 添加/删除行

python - 无法在 Mac Mavericks 上安装 python mysql 库

c++ - 在 OS X Mavericks 中从 C++ 链接 C

objective-c - 核心基础对象和保留/释放消息

cocoa - 可以有多个带有应用程序委托(delegate)对象的 Nib 吗?

cocoa - 如何在 NSTableView 中单击 NSTextFieldCell 进行编辑?

objective-c - 未收到通知回复