Re: Custom Cell Bindings
Re: Custom Cell Bindings
- Subject: Re: Custom Cell Bindings
- From: Quincey Morris <email@hidden>
- Date: Fri, 02 Sep 2011 21:52:19 -0700
On Sep 2, 2011, at 17:12 , Seth Willits wrote:
> Say I have a custom NSCell subclass (or maybe NSActionCell) which implements some custom UI for manipulating some immutable value type which I can't use any of the standard cell subclasses for. If this cell is the data cell in a table column, binding the column's content to an array controller gets the values to the custom cell and they're displayed correctly. Easy peasy.
>
> What I can't figure out for the life of me is how to change the value in the cell and get that change back into the original array. If the object is mutable and you're changing some property of it, that's straightforward, but how do you change the entire value if it's immutable? NSCell has a "value" binding, which I thought maybe would be bound to something, but it's not.
>
> As far as I can tell, there's no way to change the object value of the cell and reflect the change in the array controller's content.
TBH, I'm not sure I understand the question exactly. We might need an example of the sort of objects you're dealing with.
However, I think you're laboring under a misapprehension. The object values which are displayed in a table view *are* immutable. If they weren't, it wouldn't be possible to use NSNumber objects as cell values, for example. You're never "editing" the *object* that represents the cell value, you're "editing" the cell by replacing the value object with a different value object.
When bindings are involved, there are always two things: the bound object and the property key. The bound object may well be (I guess, has to be, really) mutable, but the value of the property key is treated as immutable. That's why, as we've discussed on this list before, you can't successfully use a NSMutableString object as an editable cell value (note: I'm not talking about a string value property of another object, but a mutable string object itself), because there's no key for the value. (For read-only purposes, the key "self" works fine, but for mutating the string you're out of luck. People have experimented with giving NSMutableString a "string" property to get around this, but this is a hack that may not be entirely successful.)
In terms of data sources rather than bindings, note that both getting and setting the object value is done via methods that simply pass relevant value objects around. There's no API that actually modifies the value objects themselves -- though, of course, if in your data source the value objects are property values of some other object, you may choose to modify the other object's property.
Does that help at all?
_______________________________________________
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