Re: Custom Cell Bindings
Re: Custom Cell Bindings
- Subject: Re: Custom Cell Bindings
- From: Ken Thomases <email@hidden>
- Date: Sun, 04 Sep 2011 00:43:37 -0500
On Sep 3, 2011, at 8:35 PM, Quincey Morris wrote:
> [I]t's possible that the table configures the NSCell by binding the correct object/property combination to it just before editing, and it really is the NSCell that makes the data model value replacement.
For what it's worth, I checked this, too. The -bind:... method on the cell is not called, at least with subclasses of NSTextFieldCell or NSButtonCell. Have you checked to see if the table view will call that if your custom cell class implements it?
On Sep 3, 2011, at 7:45 PM, Seth Willits wrote:
> As Ken pointed out in his email, when there's a NSTextFieldCell involved, NSTableView is the field editor's delegate and in the textShouldEndEditing: delegate method, the table view sends the new string off to the binding adaptor which validates and applies the value to the binding. He also said: "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."
>
> I can understand the internal classes working any way they want to, especially given that all of these views/controls existed before bindings. But what I'm expecting, is that with my custom cell, which through the table column is essentially bound to a property on my model object in the array controller, the table view should be observing objectValue of the cell while a user is interacting with it, and if the cell value changes, it should be (like it does with the standard NSCell subclasses) passing it off to the bindings adapter for validation and application to the binding.
It appears to not observe the cell's objectValue but relies on the cell invoking -sendAction:to: to inform it when the objectValue has changed.
> Bindings are *bi*directional, but apparently, when you bind an array controller to a table column when the table column has a custom cell, the binding is really only unidirectional. By that, I mean whenever the model property changes, the table view redraws it with the custom cell, but AFAICT, there's no support for changing the value in the custom cell/table view to have it update the model.
It seems too early to conclude that, at this point.
On Sep 3, 2011, at 10:20 PM, Seth Willits wrote:
> Hence, my thinking is since it doesn't work right out of the box as I'd expect, then perhaps there's some undocumented thing I'm supposed to be doing in my NSActionCell subclass which is half of the implementation. As in, perhaps my cell subclass is supposed to do X so the table view can correctly do Y to propagate the value. That's what I'm asking.
I believe that invoking -sendAction:to: on the table view is the X you're looking for.
> On Sep 3, 2011, at 1:15 AM, Ken Thomases wrote:
>
>> The default implementation of -[NSCell trackMouse:inRect:ofView:untilMouseUp:] takes care of invoking -sendAction:to: for you.
>
> Yes, but the action and target are both nil and the table does not hook the action up to itself to do the right thing, so nothing is done.
In my testing, the table did not hook up the action or target either. I checked at the point of the call to -sendAction:to: and both arguments were nil/NULL. It doesn't have to set up a target or action because -sendAction:to: is invoked on itself, the table view, since that's the controlView of the cell. The mere fact that -sendAction:to: was invoked was enough to trigger the table view to check the objectValue of the cell and update the model via the binding.
Have you verified that -sendAction:to: is being invoked on the table view by your cell's mouse tracking and other event handling -- basically, anything which updates its value? Have you checked when, if ever, the table view is querying your cell's objectValue? Are you sure that your cell is reporting its new objectValue prior to calling -sendAction:to:?
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