• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSValueTransformer problem with NSTextField update
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSValueTransformer problem with NSTextField update


  • Subject: Re: NSValueTransformer problem with NSTextField update
  • From: Quincey Morris <email@hidden>
  • Date: Thu, 1 Oct 2009 09:53:13 -0700

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@hidden)

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:
This email sent to email@hidden


References: 
 >Re: NSValueTransformer problem with NSTextField update (From: Paul Bruneau <email@hidden>)

  • Prev by Date: Re: [iPhone] Application running for the very first time...
  • Next by Date: Re: NSValueTransformer problem with NSTextField update
  • Previous by thread: Re: NSValueTransformer problem with NSTextField update
  • Next by thread: Re: Mixed Core Data and "static" nodes in outline view
  • Index(es):
    • Date
    • Thread