• 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: Custom binding problem...can't figure out how to trigger a notification on set
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Subject: Re: Custom binding problem...can't figure out how to trigger a notification on set
  • From: "E. Wing" <email@hidden>
  • Date: Tue, 3 Oct 2006 14:46:38 -0700

Thanks. This got me just about there. (Turns out I needed to save the
keypath too and call setValue:forKeyPath). I'm wondering what the best
strategy is for avoiding infinite recursion is. When I call
setValueForKeyPath inside my setter, it triggers another set
notification which causes the setter to be called again (and again).

For simple values, I could check for equality and escape if there is
no change, but for NSColor, I think the fact that I have conversions
to usable color spaces in my code is making the equality comparisons
fail.

Thanks,
Eric

On 10/2/06, Mike Abdullah <email@hidden> wrote:
Well as far as my understanding of your situation is, you really
ought to do something like this:

In the bind: method of your view, make a note of the object you're
bound to.

When the background colour needs to be set by the view itself, have a
look and see if you're bound to anything.  If not, simply set the
background color.  If you are bound to something, ask that object to
setValueForKey:

Mike.

On 2 Oct 2006, at 19:16, E. Wing wrote:

> 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?
>
> Thanks,
> Eric
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Custom binding problem...can't figure out how to trigger a notification on set
      • From: mmalc crawford <email@hidden>
References: 
 >Re: Custom binding problem...can't figure out how to trigger a notification on set (From: Mike Abdullah <email@hidden>)

  • Prev by Date: Re: Bezier Path Arc Problem
  • Next by Date: Re: NSCell editing weirdness
  • Previous by thread: Re: Custom binding problem...can't figure out how to trigger a notification on set
  • Next by thread: Re: Custom binding problem...can't figure out how to trigger a notification on set
  • Index(es):
    • Date
    • Thread