Binding values in a preferences window for live updates

  • I want to calculate a value based on the values and/or indexes of
    NSPopUpButtons (and checkbox states) in a Preferences Window, then
    NSTextField-that back into the same window.  The value should appear on
    awakeFromNib and refresh upon any change in selection - a recalculate
    button would suck.

    I seem to be stuck in an infinite loop with a screenful of documentation
    and webpages (plus  Hillegass's book) trying to figure out what is
    relevant in the NSPopUp Inspector's bindings page, and then figure out
    how the calculation method is triggered and fed.  A kick-start would be
    appreciated.

    vonhinx
    -------------------------
    be kind to newbies -`^ ^ ´-
  • On Dec 12, 2007, at 10:35 PM, hinx wrote:

    > I want to calculate a value based on the values and/or indexes of
    > NSPopUpButtons (and checkbox states) in a Preferences Window, then
    > NSTextField-that back into the same window.  The value should appear
    > on
    > awakeFromNib and refresh upon any change in selection - a recalculate
    > button would suck.
    >
    It's not clear what this means.

    To step back, you typically ultimately bind to a model value, you
    don't (insofar as I can tell you're trying to do) bind from one view
    to another.  Decide what model value it is you want to represent, then
    bind to that.

    mmalc
  • At 7:51 PM +1100 12/13/07, hinx wrote:
    > How to "bind each control to a preferences setting" is what I was
    > probably trying to ask :)

    See the "User Defaults Programming Topics for Cocoa" manual.  Then
    read the NSUserDefaults class documentation.  You'll also find "man
    defaults" helpful.

    >
    >> You don't really want to do this.  Break it into several steps.
    >> Consider that the Model part of MVC should work without any UI.
    >
    > Oh yes I think I most definitely want to do it.  The whole point of the
    > game's preferences window is to set degrees of difficulty and view the
    > maximum potential score with such settings.

    You don't want to do it the way you described doing it--that will
    make your brain melt.  The conventions of Cocoa are not just
    religious pedantry, as conventions sometimes are.  You really have to
    follow them in order to make Cocoa work for you.

    I believe your task can be accomplished, in a minimal way, by writing
    only one method:  one which reads the current values of the defaults
    and applies your business logic to compute a maximum potential score.
    You do also need to implement initial values for the defaults and
    register your defaults, as described in the above-referenced manual.

    Bind the output field to that maximumPotentialScore method, and
    uncheck the "editable" box.  Bind the parameter controls (checkboxes,
    sliders, etc) to user default keys (Bind to: Shared User Defaults,
    Controller Key: values, Model KeyPath: to match what you're using in
    your code).  I highly recommend defining global variables for the
    defaults' key strings--make the compiler do the work, not you.

    --
    Hal Mueller                <hal...>
    Mobile Geographics LLC    http://www.mobilegeographics.com/
  • If you are using computed properties in your model, one thing you want
    to do is register dependent keys for such properties.  Otherwise, changing
    something like a bound popup will not show up in dependents until something
    (like a window activation event) forces a redraw.  (I just faced this issue
    myself yesterday.)  In your model code, for each computed property add a
    dependency statement similar to the following ("midColorHidden" is the
    computed property):

    + (void)initialize {
        [self setKeys:[NSArray arrayWithObject:@"fillMode"]
    triggerChangeNotificationsForDependentKey:@"midColorHidden"];

    or

        [self setKeys:[NSArray arrayWithObjects:@"fillMode", @"checkBox", nil]
    triggerChangeNotificationsForDependentKey:@"midColorHidden"];

    etc.

    }

    >
    > I want to calculate a value based on the values and/or indexes of
    > NSPopUpButtons (and checkbox states) in a Preferences Window, then
    > NSTextField-that back into the same window.  The value should appear on
    > awakeFromNib and refresh upon any change in selection - a recalculate
    > button would suck.
    >
    > I seem to be stuck in an infinite loop with a screenful of documentation
    > and webpages (plus  Hillegass's book) trying to figure out what is
    > relevant in the NSPopUp Inspector's bindings page, and then figure out
    > how the calculation method is triggered and fed.  A kick-start would be
    > appreciated.
    >
    >
    > vonhinx
    > -------------------------
    > be kind to newbies -`^ ^ ´-
    >
previous month december 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Go to today