Re: Add keys programatically to NSArrayController? [solved]
Re: Add keys programatically to NSArrayController? [solved]
- Subject: Re: Add keys programatically to NSArrayController? [solved]
- From: Rick Hoge <email@hidden>
- Date: Sat, 31 Jul 2004 08:11:05 -0400
Ok after some more digging I think I found a solution. It is not
adding keys to the array controller.
Instead:
Keep the collection of attributes you want to represent in new columns
in an NSMutableDictionary. Call the collection - say - someObjects.
In IB manually add the key "someObjects" to the NSArrayController in
the nib file for the table
When adding a column to the table during program execution, add a
dictionary entry with key @"new1" to the someObjects ivar of each
object in the array. This will be the contents of the table cell for
that object in the new column.
Then (this is in code now) bind the first new column using
[newColumn bind:@"value" toObject:tableController
withKeyPath:@"arrangedObjects.someObjects.new1" options:nil];
The default implementation of valueForKeyPath will then get the
dictionary someObjects and return the result of sending it
valueForKey:@"new1"
This is pretty cool - I had not used the someObject.someKey
functionality before. I think bindings are awesome - in the end my new
columns scheme took about ten lines of code, but hope the retain cycle
thing will be fixed soon... (yes I've filed a bug).
Rick
On Jul 31, 2004, at 7:23 AM, Rick Hoge wrote:
Is there any way, using Objective-C calls, to add new keys to an
existing instance of NSArrayController?
I have an NSTableView in which I'd like to be able to allow the user
to add an arbitrary number of columns whose value would be bound to
keys in a custom class. My plan was to generate new keys
automatically (e.g. @"key1",@" key2", ...) and have my custom class
provide appropriate values by parsing these keys in valueForKey: .
The arbitrary number of columns would correspond to an aribitrary
number of object attributes in the custom class
For this scheme to work, I need to be able to add @"key1" to the
NSArrayController I'm using to serve my list of objects to the table
when a column is added. Such functionality does not seem to be
included in the docs for NSObjectController and NSArrayController -
anyone know if it is possible?
Obviously my 'arbitrary number of object attributes' would be best
modeled as an NSArray instance variable in the custom class. I don'
know how you would associate specific elements in the array with the
appropriate columns through bindings though. I'm already using
bindings in this table and, as this has been working well for me (up
to this), would like to stick to this approach if possible.
Thanks for any suggestions,
Rick
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.