Re: NSFormatter, bindings and units
Re: NSFormatter, bindings and units
- Subject: Re: NSFormatter, bindings and units
- From: Steve Sims <email@hidden>
- Date: Tue, 15 Jun 2004 12:06:06 -0400
Hi Glenn,
On 15 Jun 2004, at 09:31, Glenn Andreas wrote:
So I've got a model object that keeps track of measurements in
pixels, and I use bindings to display these values in a nice little
NSForm. However, since the user may want to use something like inches
or centimeters to specify these values, I've got an NSFormatter that
converts from pixels to whatever the default is (and accepts any
possible unit and converts it back). Everything works like a charm.
So I add a preference to change what the default unit is, and want all
the forms to update accordingly - seems like a pretty common task. So
I have the model object get notified when that preference value is
changed, and then explicitly set a "dummy" ivar, for whom I've already
added to the list of dependancies to trigger updates for all my
fields.
For objects that are actual string values which generate new values
when the units change, this works great. However, for those variables
bound to the form, nothing happens. It appears that since the
underlying _value_ doesn't actually change (72.0 is still 72.0 even
though it should be displayed as 1" instead of 2.54 cm) only the
_formatted_ representation, it doesn't update. If I tab into that
field, it calls the formatter again and gets the correct format.
What it sounds like you need to do is do manual observing of your dummy
ivar and post change notifications for the values you wish to be
updated. Within your setter method for your dummy ivar in your data
model you'll need to do a "willChangeValueForKey" and a
"didChangeValueForKey". Whenever dummy changes it will look to the
bindings system like the other values change too so they should get
changed. You don't actually need to change the other values at all.
Check the KVO documentation for more info on doing this, especially
under the section "Manual Observer Notification".
Steve
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.