• 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: NSFormatter, bindings and units
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSFormatter, bindings and units


  • Subject: Re: NSFormatter, bindings and units
  • From: Glenn Andreas <email@hidden>
  • Date: Tue, 15 Jun 2004 11:22:27 -0500

At 12:06 PM -0400 6/15/04, Steve Sims wrote:
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.

That is what I'm doing. The problem, as near as I can tell, is that the value isn't actually changing.

So, I've got an ivar "length" (let's say it has the value 72.0), which is bound to a cell in form (the cell's value is bound to the object, key "length"). That cell has a formatter that will display either 1", 2.54 cm, or 72 pt, depending on the user's preference (the user can actually type any of the three and the formatter will convert accoridngly).

When the user changes the preference for the units, I manually observe that change, update a dummy value (which then has dependancies to "length").

However, when the user changes from inches to cm, the value "length" isn't actually changed (it's still 72.0), so it appears that the binding layer is "smart" enough to not update the cell's value, even though the formatter will produce a different string value.

So as near as I can tell, the formatter is downstream from the binding logic.

My best workaround so far is to bind the textColor to this "unitsChanged" field (and then change it to something like red and back to black) and then it will update correctly, but that seems pretty skanky (but better than changing the value of length to something else and setting it back).

--
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.


References: 
 >NSFormatter, bindings and units (From: Glenn Andreas <email@hidden>)
 >Re: NSFormatter, bindings and units (From: Steve Sims <email@hidden>)

  • Prev by Date: NSTextView and White Space
  • Next by Date: Re: Getting cartesian values from Bezier curve question
  • Previous by thread: Re: NSFormatter, bindings and units
  • Next by thread: Re: option-click hides apps
  • Index(es):
    • Date
    • Thread