Re: NSCell subclass with custom binding
Re: NSCell subclass with custom binding
- Subject: Re: NSCell subclass with custom binding
- From: Scott Stevenson <email@hidden>
- Date: Sat, 21 Oct 2006 14:49:31 -0700
On Oct 21, 2006, at 8:40 AM, Stephan Cleaves wrote:
Since the binding is custom the NSTableColumn cannot be bound to it
because of course it knows nothing about it. I'm not sure if there
is a way to get NSTableColumns to know about new bindings
programmatically.
You can't do it graphically, but you can usually do it
programmatically using the KVB protocol methods. In fact, you can
even bind things that aren't explicitly exposed (at least sometimes).
I don't know exactly what NSTableColumn does to correctly provide
the NSCell with its value but it seems like it probably gets the
value via the binding and iterates over the values for the visible
cells.
The table column will just use whatever keypath you give it. So if
you bind its 'value' property to:
SomeArrayController.arrangedObjects.name:
It will call 'name' or 'setName' on each model object. The result of
'name' on the model object will be set as the object value for the
cell that is currently being displayed.
I haven't done exactly what you're describing, but I think if your
subclass does the right thing in -value and -setValue (and by "right
thing," I mean properly update its display), then I *think* you
should be set.
Anyway, my questions are: Is there a way to get NSTableColumn to
know about custom bindings either programmatically or through IB
It should be something of the flavor:
[column
bind:@"value"
toObject:arrayController
withKeyPath:@"arrangedObjects.someProperty"
options:nil];
You'd probably make something method called -setupCustomBindings and
call that in -awakeFromNib.
There is also no point in binding the NSActionCell subclass itself
because it only wants a single value and binding to
arrangedObjects.bindingname of the NSArrayController would result
in an array.
You could also possibly get away with dropping an NSButtonCell in
your table in IB (since it's an action cell), setup the bindings in
IB as well, then swap in your custom data cell at runtime. If that
works, it would be a simpler solution since you don't have to setup
bindings programmatically.
I did something like this, but with an NSImageCell subclass instead:
http://theocacao.com/document.page/196
- Scott
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden