Re: NSValueTransformer problem with NSTextField update
Re: NSValueTransformer problem with NSTextField update
- Subject: Re: NSValueTransformer problem with NSTextField update
- From: Quincey Morris <email@hidden>
- Date: Thu, 1 Oct 2009 12:47:07 -0700
On Oct 1, 2009, at 12:26, Paul Bruneau wrote:
The other way to approach this is to add a second set of properties
-- the formatted string values of your numeric properties -- that
are dependent on the numeric ones, and bind to the string
properties instead. It's a PITA to code it all, but it puts the
formatting all in your hands.
hmm, but will my users be able to make changes to text fields that
are bound to dependent string values like that?
Well, yes, though it takes a bit of care not to end up going round in
KVO circles.
You can set up your string-property *getter* to generate the string
dynamically, so you don't have to store the value. Then set up your
string-property *setter* just call the numerical property setter with
a suitable value. Equality of numeric values doesn't matter here.
Simply invoking the numerical value setter triggers the KVO
notification, which triggers the string-property dependent key
notification, which causes your user interface to update from the
dynamically regenerated string property value.
If you're using some kind of invocation-based undo, you want to make
sure you keep the string-value property out of it, though.
BTW, you can put the numeric property in your data model, and add the
string property to (say) your window controller. It's more or less the
same thing, better partitioned, but with a slightly more complicated
dependency.
The key thing you said, IS, was "aside from transformed values"
which of course is exactly the case I am interested in. I am a
little surprised that more developers haven't wanted their text
fields to update to the reverse-transformed value after the user
commits the change. It seems that Cocoa could easily look to see if
a transformer is on the field, and do a reverse transform after entry.
I continue to be surprised that no one else has been bothered by
this difference in behavior between these common UI types. Maybe
transformers are very rarely used?
Now that you mention it, I've done exactly what you are trying to do,
except I was using formatted time codes instead of fractions. I want
to say that it was working correctly, but I can't swear to it. I'll
have to go back to that app and see if it really does prettify the
string representation when the underlying value doesn't change.
_______________________________________________
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