Re: Custom binding problem...can't figure out how to trigger a notification on set

  • (Sorry if this is a repost, but as far as I can tell, my followups
    have not been getting to the list.)

    Sorry for the confusion. So what I'm after is the ability to make
    changes internal to my view subclass, but still some how notifiy a
    bound controller (if it exists) that I made these changes so anything
    that is bound to my view will know something has changed and will stay
    in sync (such as the NSColorWell).

    So some examples of why I want this:
    - On creation of my view class, I may internally set a default color
    (such as green), but how do I get the bound color well to start at
    green (it starts at black currently and not green).

    - My custom view may handle events and I may want to do something like this:
    - (void) mouseDown:(NSEvent*)the_event
      [self setBackgroundColor:[NSColor blueColor]];

    Since the event is defined in the view subclass, how do I notify the
    controller about this change?
    (Maybe this is somewhat analogous to the NSTableView in how its
    mouseDown can change the current selected item and other bound things
    will notice the change event?)

    - Somewhat hypothetical, but maybe my view class has a private NSTimer
    that fires off periodically and decides to change the color (perhaps
    to reflect the time of day, or perhaps I'm just doing color
    animation). Again, I would like to set a new color like in the
    mouseDown example, but how do I get the NSColorWell to keep up?


    On 10/2/06, Mike Abdullah <mike.abdullah...> wrote:
    > Well to be honest, I'm not entirely sure I understand what you're
    > after here!
    > I understand that you're creating a custom NSView subclass.  As part
    > of this subclass's functionality, it should have a changeable
    > background colour.  When using this, the user will add an
    > NSObjectController to their nib and then bind the backgroundColor of
    > the view to this.
    > So, is what you're now asking about, the palette that appears in
    > Interface Builder to handle the customisation of the view in IB?
    > Mike.
    > On 29 Sep 2006, at 23:07, E. Wing wrote:
    >> Thank you for the reply. That makes a lot of sense. But here's a
    >> follow up question. Can you tell me how I might solve this problem if
    >> I was trying to make a change within MyCustomView class directly? My
    >> motivation is that I'm writing a stand-alone library palette for the
    >> view that can be setup through Interface Builder. So it's up to a user
    >> of my palette to provide the object controller and other connections.
    >> So imagine if my view needed to change its color internally, like a
    >> reset, or maybe a time triggered color change, or maybe something that
    >> is triggered on the View's mouseDown event. How do I notifiy the
    >> object controller about this change?
    >> Thanks,
    >> Eric
    >> On 9/29/06, Mike Abdullah <mike.abdullah...> wrote:
    >>> Hi Eric, I can tell you exactly what your problem is :)
    >>> You have an NSObjectController to which you are binding your custom
    >>> view and the color well.  That is fine and works as it should.
    >>> When you set the color using the well, this sets the color of the
    >>> NSObjectController and the view then picks up that this has happened.
    >>> However, when you set the color using one of the buttons, you are not
    >>> setting the color of the NSObjectController like you should. Instead
    >>> you are setting the color of the view directly.  By doing this, the
    >>> color well never "sees" this change.
    >>> So, simply change your calls to something like:
    >>> [colorController setValue: [NSColor redColor] forKey:
    >>> @"backgroundColor"];
    >>> Mike.
previous month october 2006 next month
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