Hello Cocoa listers.

What is the best/right way to obtain the context object for a piece of text that has been edited by the editing system (i.e. in a cell in NSOutlineView) once the textDidEndEditing notification is delivered to an observer?

This is the second or third time I have added text editors in controls where I've wanted to capture the final state of the editor to set it into an object (i.e. not doing this automatically with binding). Each case has been a bit different. In this case I have a fairly straight-forward NSOutlineView and a custom cell really just to do some specific text editing stuff.

Pretty much everything is working fine - but unlike previous occasions when I have used the field editor, in this case once I get my "textDidEndEditing" notification, I need to find the object that the editor is representing in order to update a property. What I'm wondering is how this is _supposed_ to be done.

The actual notification of textDidEndEditing does not include much contextual information AFAICS. It does provide you with the NSText object that handled the editing, from which I can happily get the final text. However, I'm not sure what the "best practice" is for obtaining the 'represented object' to which this text should be assigned. I've chosen to implement the notification method in my custom cell class, which works fine, but the instance of this cell appears is not initialised with outlineView:willDisplayCell:forTableColumn:item. Therefore the cell's representedObject is nil and I cannot use this way to get the context.

I could simply ask the control (the outline view) what the currently selected row is, and get the object to update from the arrangedObjects of my NSTreeController. This seems a very 'long way round' though. I suspect I'm simply missing some way to have the editing system remember a context object for me and pick it up later (but I don't see anything obviously doing this in the NSText interface, that I'm guaranteed to be able to obtain and use from the textDidEndEditing notification).

-- Luke



_______________________________________________

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