On Oct 1, 2009, at 05:49, Paul Bruneau wrote:

I got no responses to my query, which probably means I asked something poorly, but I needed to write another NSValueTransformer for my project (to convert dollars into pennies and back) and I saw the same behavior so I thought I'd ask again.

To summarize: When I use my NSValueTransformers in a cell of an NSTableView, the entered value gets transformed twice--once going in to my model, then it comes back out to the view--which is good because it cleans up the entered value and makes it be optimal (as outlined in my original question below).

But when I use the transformer on a regular NSTextField, I don't get that benefit. It properly transforms the value and the correct value gets stored in my model, but the reverse transformation doesn't fire like it does when used in the table view.

I *suspect* the answer is that there's no particular guarantee (in the sense of no API contract) that the reverse transformation will be run at any point as a result of editing the text. It's easy to see why it would happen in the table view case, simply because the cell must be redrawn (because of the removal of the field editor text field) at the end of editing.

So, if your general intent is to prettify the text string entered by the user, then you should use the appropriate mechanism to ensure that -- validation. Write a validate<Key> method for the underlying property, and modify the ioValue parameter before returning YES. This should get your freestanding text fields formatted properly when a regular text field is edited. (Within this method, you'd run your value transformer in reverse, of course.)

A NSFormatter is another way to go, but it seems like a lot more trouble for behavior that validate<Key> is designed to provide easily.


_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to