NSFormatter, bindings and units
NSFormatter, bindings and units
- Subject: NSFormatter, bindings and units
- From: Glenn Andreas <email@hidden>
- Date: Tue, 15 Jun 2004 08:31:40 -0500
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.
If I manually change the value of that ivar (and then change it back
"[self setLength: length+1.0]; [self setLength: length-1.0]"), it
will update - but that messes with the dirty state. If I just change
the value explicitly to the current value ("[self setLength:
length]"), nothing happens.
Short of explicitly reload every single cell in every form, is there
a way to get bindings to reload the value (and redisplay the
formatted value) even though that value hasn't changed (just the
formatted version).
I originally tried to use a value transformer to convert from pixels
to the appropriate units (and then a format string to display the
value with suffix) but that didn't work as well as a NSFormatter
attached to the cell did.
--
Glenn Andreas email@hidden
mondo blobbo, Cythera, Theldrow, oh my!
Mad, Bad, and Dangerous to Know
_______________________________________________
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.