1

I've encountered a few scenarios where I'd like to show some entries in an NSDictionary in an NSTableView. (My instincts to user an NSDictionaryController are always foiled by the need to make every object implement copyWithZone, which I find to be an absurd requirement that is fatal to usability...)

Instead, I'm trying to bind an NSArrayController to the allValues property of an NSDictionary, with the intent of binding respective columns of the table various properties of the objects in the array. However, I can't find a correct way to specify this binding within Cocoa, via the Controller Key and Model Key Path properties of the array controller.

When I attempt to bind the array directly to allValues, the array controller's arrangedObjects property is constantly empty - even when objects are added to the dictionary, when the addition is enclosed by [dictionary willChangeValueForKey: @"allValues"] and [dictionary didChangeValueForKey: @"allValues"] calls, even after calling setContent: on the array controller after adding the object.

Of course, I found this Stack Overflow thread:

Binding to an NSDictionary's "allValues" array

...and tried various versions of @"@allValues" in the Model Key Path field, but none produced the desired results.

So here's my question: If I have ArrayControllerOne bound to an object, and I'd like to bind ArrayControllerTwo to the allValues property of an NSDictionary property (called "instances") within ArrayControllerOne.selection, what should I enter in the Controller Key and Model Key Path fields?

Thanks in advance...

4

1 回答 1

2

您一定漏掉了一个,因为我发现您可以使用 dict.@allValues(不带引号)将数组控制器的内容数组绑定到字典的 allValues,其中 dict 是字典的属性名称。为什么会这样,我不知道——我找不到任何文档。

顺便说一句,如果我在字典中添加一个新的键值对,我使用 self.dict = _dict; 让表视图更新。

于 2012-09-21T04:57:37.610 回答