Re: Custom Cell Bindings
Re: Custom Cell Bindings
- Subject: Re: Custom Cell Bindings
- From: Quincey Morris <email@hidden>
- Date: Sat, 03 Sep 2011 00:44:15 -0700
On Sep 2, 2011, at 23:16 , Seth Willits wrote:
> I'm well aware of all of that.
Well, I thought you were, but I still think the issue is in the way you're asking your question. See below, where I have another go at getting it right.
> I explicitly stated the object is immutable because it is very possible to supply a mutable object as the object value of a custom cell and modify the object value's properties from within the cell. Doing that is very straightforward.
Yes, OK, it is, though I'm not sure it *should* do this. If you're talking about the cell's "objectValue", then it's an object value -- the implication being that it's immutable (or, rather, used immutably) and there's a 'setObjectValue' method to change it ("it" == "the cell's object value property"). If you're changing the value object itself, I think you're abusing NSCell.
But that's just "I think". I can't say I know for sure. Someone who understood these things in NeXTStep days would need to chime in with the intended semantics of NSCell object values.
> What is not straightforward is if the object value is immutable, how I'm supposed to have the new immutable object in the cell actually update the property of an object in the array controller the table column is bound to.
Isn't this exactly the cell [in the sense of table (row, column), not the sense of NSCell] editing mechanism of NSTableView? IOW, the problem isn't solved at the level of the NSCell, which clearly doesn't have enough information, but at the level of the table, which does. As you're well aware, either the KVC or the data source patterns take care of replacing the immutable value.
> An array controller is managing a bunch of Foo objects, each Foo has a bar property. There's a table view, with a column, where the column is bound to the array controller's arrangedObjects.bar. The table column has a custom BarCell which displays and edits Bar objects.
>
> With the binding setup, the BarCell can easily display the bar values as is, but after the user interacts with the cell if there's a new Bar value created, how do you actually have it update the bar property in the corresponding Foo object?
Ditto.
> 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.
Maybe I'm being dense, but this part makes no sense to me. If by "editing" you mean the typing of characters and deleting, cutting, copying, pasting, etc, within the text field, then this is local state of the cell and isn't changing the object value (if for no other reason that it's happening in the field editor rather than your cell). The value gets replaced *wholesale* when (say) Return or Tab is pressed -- which is perhaps what you meant by "editing" -- and it uses the above-described mechanisms, with no string mutability considerations.
> NSCell has a value binding and I'm surprised it's not already being used here.
Again, I don't understand. What is "here"? A binding uses a two-part mechanism, just like KVC. The value represented by the binding-name (e.g "Value") is still a value object. It's the bound-to object providing this value that's mutable.
Really, I'm sorry if I'm misunderstanding, but I think one of two things is going on here:
1. You're trying to use a NSCell to modify a value object. That may work fine, but there's a conceptual difference that doesn't fit the way we usually think about these things.
2. Instead of passing a value object to your custom NSCell, perhaps you should be passing the (mutable) object that the value object is a property of, plus something that identifies the value object (a key, a binding name or perhaps it's implicit in the custom NSCell code). I can't remember offhand, but I presume that you could use the "Value" binding and look up the bound-to object and the binding name (and hence key?) from the NSCell's binding info.
_______________________________________________
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