The docs that do exist concerning the way to map arbitrary objects (such as ones that contain a 'name' attribute in my case) onto text cells have to do with NSFormatter. The latter is clearly how one converts 'simple' values from an object form to a stringified form and v.v. The problem with using a subclass of NSFormatter in my case is that I only want to affect a change to the 'name' attribute on an otherwise persistent object (actually a Core Data object). I don't want to be creating new 'value' objects every time the user edits a character in the cell. NSFormatter's getObjectValue:forString:errorDescription: method is really supposed to return a new object if parsing of the string is successful.

Nevertheless, it is possible to make a subclass of NSFormatter that is constructed explicitly to deal with the object that becomes set on the cell (via setObjectValue:) from the column binding. The aforementioned method can then forward the received strings to this object as changes to its name attribute. This is a pretty nasty abuse of NSFormatter, but it 'works' so long as the object can stomach 'continuous' updates as the user types.

What this doesn't do though, is fix the KVC error mentioned below. This can be suppressed by implementing -setValue:forUndefinedKey: on "MyClass" and handling the empty string "key" that gets sent - essentially to ignore the value (which is curiously the cell's placeholder string "Text Cell") further indicating that things are pretty screwed up!

So, I really think there must be a 'proper' way to get the editor to pick up and return the value (name) I need editing from my cell's model object, but I'm still searching for the white magic, having dabbled in the darker sort.

-- Luke



On 30-Jan-09, at 9:32 PM, Luke Evans wrote:

The Cocoa docs seem silent on how to achieve this.

I have an NSTextFieldCell subclass that gets sent an object from bindings. The reason for sending it an object is that I want the cell to display a number of the object's attributes - which it does nicely through custom drawing. Now I need to allow editing of the text in the cell. I have overridden:
editWithFrame:inView:editor:delegate:event:
and its buddy:
selectWithFrame:inView:editor:delegate:start:length:

These bring up the text editor nicely. However, as I have an object at the cell, I need to present a string to this mechanism (the name property of my object), and similarly I need to somehow obtain the value from the editor when editing has finished. At the moment, the default behaviour has the editor coming up with placeholder text, and when editing is finished I get an KVC error, e.g.: Error setting value for key path of object <MyClass: 0x1b385c0> (...) from bound object <NSTableColumn: 0x1b1ab20>(null)): [<MyClass 0x1b385c0> setValue:forUndefinedKey:]: the entity MyClass is not key value coding-compliant for the key .

Does anyone know how to wire up the editing so that I can provide initial text to the editor and prevent whoever it is from attempting to set the final value directly onto the bound object (which it clearly doesn't know how to do as it's a particular attribute of the object at the cell)?





_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to