If anyone is interested in seeing this issue with NSValueTransformer and how it performs in a table vs in a text field, I had filed a bug (7268704) on it and was asked to provide an example. So I thought I'd share my example:

http://ethicalpaul.com/share/transformer_sample_code.zip

It's based on the WithBindings sample code from mmalc.

When you run the project you'll see the familiar WithBindings interface. I have added a new instance variable to the document type which is an NSInteger called numberOf32nds.

On the interface, I have added a new column to the table (marked "Inches") and in the detail view below the table I have added a text field also marked "Inches". I have bound them to the numberOf32nds instance variable using my transformer called "ThirtySecondsToInchesTransformer".

First, create a new Bookmark and edit its "Inches" value in the table. Try entering something like: 32 3/4 You will see upon pressing Return that the value is "cleaned up" by being sent into the transformer and then back out again. It comes out: 32-3/4".

You will see this value also gets updated in the Text field below thanks to the Bindings system. (You can also use a shorthand data entry method of <inches>.<32nds> such as entering 32.5 and it will get transformed to 32-5/32")

Now, go down below to the edit field and try the same thing. You will see that the entered value does not get "cleaned up", but remains how you entered it. Of course, the "cleaned up" version does get updated in the table (again, thanks Bindings).

It seems like other people would have had issues with this, but sometimes I do things differently than other people :)

On Sep 17, 2009, at 2:15 PM, Paul Bruneau wrote:

Greetings-

I have written a subclass of NSValueTransformer which converts an NSString from something like "1-1/2" to an NSNumber with a value of 48 for my model to store (converts inches and fractions to number of 32nds). It also does the reverse transformation.

This is working perfectly for columns in an NSTableView that I have bound to NSInteger properties in a model object. If I enter: 1 1/2 and press return, it will store the correct number, and it will even instantly update the cell to contain the "cleaned up" version of the fraction which would be: 1-1/2" (which I find very desirable). So it's like the the transformer is working in the normal direction to store the correct value, then the reverse transformer is also getting called and updating the text cell.

So then I had need to use this transformer for a few NSTextFields on the same window as the table and here is the weirdness:

When I enter the text (say 1 1/2) and press return, the correct value is getting set in model BUT the field content is not getting updated like it does in the NSTableView. It will select the text, but it will not replace it with its "cleaned up" content which should be: 1-1/2"

If I choose Undo (and also Redo), then the "cleaned up" text appears. Or if I close the window, and then re-open it, then the "cleaned up" text is correctly displayed (ditto for the document).

Does anyone have any idea why I am seeing this difference between the table columns and the text fields?

Is it normal for a transformer to do that nice "clean up" after return is hit that I am seeing in my table, or is that being caused by some lucky accident in my case?

Thank you

_______________________________________________

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