Re: Custom Cell Bindings
Re: Custom Cell Bindings
- Subject: Re: Custom Cell Bindings
- From: Ken Thomases <email@hidden>
- Date: Sat, 03 Sep 2011 03:15:36 -0500
On Sep 3, 2011, at 1:16 AM, Seth Willits wrote:
> The scenario is analogous to a custom text field cell where the cell is displaying and editing an immutable NSString. With NSTextFieldCell when you edit the text, the table view and cell cooperate to update value at the other end of the binding. How do you do that same kind of thing with your own custom objects. I'm pretty sure I could solve it by slopping a bunch of glue into the table view and/or delegate, but that's messy. It seems to me there's a single simple missing step which would make a custom cell completely support bindings when in a table column. NSCell has a value binding and I'm surprised it's not already being used here.
By watching what the framework is doing, it appears that, for a text field cell, the table view is the delegate of the field editor and gets notified when editing finishes. It then takes care of updating the property to which the relevant column is bound on the relevant object for that row.
For a checkbox button cell, the cell invokes -[NSControl sendAction:to:] on its controlView (the table view) to send its action to its target. In the case I tested, the cell had neither an action or a target, but it still did this. Again, the table view took the responsibility of updating the model value through the binding.
The default implementation of -[NSCell trackMouse:inRect:ofView:untilMouseUp:] takes care of invoking -sendAction:to: for you. Unless you've overridden that in your custom cell, which is discouraged, you should get this for free.
Just for completeness, I tried using the keyboard to toggle the checkbox cell which resulted in -[NSButtonCell performClick:] being called, which called sendAction:to:, too. Again, that provoked the table view to update the model value through the binding.
In general, the cell does not modify the model object. It is only responsible for reporting its current value and for sending its action. As Quincey said, if the cell's objectValue happens to be mutable that doesn't mean the cell is entitled to mutate it. It should replace it -- stop referring to it and start referring to a different object -- when it needs to take on a new value.
Regards,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden