On 11 Dec 2009, at 22:54, Keary Suska wrote:

> On Dec 11, 2009, at 12:45 AM, Gerriet M. Denkmann wrote:
> 
>> I have a window with an NSTableView which is bound to an NSArrayController 
>> which has as content an NSMutableArray called "theArrayOfDictionaries".
>> Works fine.
>> 
>> "theArrayOfDictionaries" contains NSMutableDictionaries.
>> So I added another NSTableView to my window, bound to an 
>> NSDictionaryController, which has it's content bound to 
>> NSArrayController.selection.
>> 
>> But the documentation says about selection: "proxy object representing the 
>> receiver’s selection".
>> And it's no surprise that I get an exception: "Cannot create NSDictionary 
>> from object [...] of class _NSControllerObjectProxy"
>> 
>> Well, everything behaves as documented - no reason to complain.
>> 
>> But: how to I populate my NSDictionaryController with the 
>> NSMutableDictionary currently selected in my NSArrayController?
>> And also: make sure that any changes done in this current dictionary (the 
>> NSTableViews will be editable) get back into "theArrayOfDictionaries"?
> 
> You will have to maintain the currently selected object in your model.
> 
> HTH,

This certainly helps - if only in destroying my hopes for an easy solution.

So: you are telling me to observe the selection of my NSArrayController 
updating some property like currentlySelectedArrayElement whenever the 
selection changes.
And setting the content of my NSDictionaryController to this 
"currentlySelectedArrayElement".

And also observing currentlySelectedArrayElement - so that in case the user did 
edit it's NSTableVIew the new thing can be reinserted into my NSArray.

Sounds like much work.
The more so, because it is possible to bind a controllers content to 
NSDictionaryControllers selection.value without any problems - so that the 
inability to bind something to NSArrayController selection seems a kind of 
unexpected limitation.
But this is by the way.


Well, in the end I tried another solution:

My NSArray not longer contains NSDictionaries, but a new class GmdContent which 
has just one property called realContent (which contains the NSDictionary).

And now I can bind the content of the NSDictionaryController to 
NSArrayController selection.realContent and everything works perfectly - 
changes done in the TableView of my Dictionary automatically get inserted into 
my Array.

Question: Is this really a very clever idea - or (as I am about to find out 
later) an awfully silly one?

And what about another idea I had:
Replace the NSArray (a0, a1, ..., an ) with an NSDictionary: ( 0 → a0, 1 → a1, 
..., n → an )?
I have not tried this yet, but it sounds a plausible workaround. Or is it?


Kind regards,

Gerriet.

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to