Hi again-

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.

In tableview:
1. type: 1 1/2
2. press return
3. 1-1/2" is now displayed (the cleaned up, doubly-transformed string)

In textfield:
1. type: 1 1/2
2. press return
3. 1 1/2 is displayed (no change)
4. press undo
5. press redo
6. 1-1/2" is displayed (the cleaned up, doubly-transformed string)

Any help appreciated

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