• 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: Stuck in basic bindings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Stuck in basic bindings


  • Subject: Re: Stuck in basic bindings
  • From: Shawn Erickson <email@hidden>
  • Date: Wed, 18 Jan 2006 13:55:20 -0800

On 1/18/06, Francis Derive <email@hidden> wrote:
>
> On Jan 18, 2006, at 8:06 PM, Camillo Lugaresi wrote:
> >
> > Yes, **IF** mouseLocation exists and is key-value observable.
> >
> >>>> - (void) mouseDown:(NSEvent *)event {
> >>>>    mouseLocation = [self convertPoint:[event locationInWindow]
> >>>> fromView:nil];
> >>>>    NSLog(@"fdeGradientView -- mouseDown - mouseLocation.x:%f
> >>>> mouseLocation.y:%f", mouseLocation.x, mouseLocation.y);
> >>>>    NSLog(@"fdeGradientView -- mouseDown - mouseXlocation:%f
> >>>> mouseYlocation:%f", mouseXlocation, mouseYlocation);
> >>>>
> >>>>    [self setNeedsDisplay:YES];
> >>>> }
> >
> > You are not changing mouseLocation in a KVO-compliant way, so it's
> > normal that change notifications are not being triggered. You can
> > define a setMouseLocation accessor and call it inside mouseDown, or
> > bracket direct assignments to the mouseLocation ivar with
> > willChangeValueForKey:/didChangeValueForKey:.
> >
> > Camillo
>
> Camillo,
>
> I feel confused after all my attempts and variations. Let me say :
>         - mouseLocation always existed as an ivar, and still is, with its
> accessors :
>                 - (NSPoint) mouseLocation {
>                         return mouseLocation;
>                 }
>
>                 - (void) setMouseLocation: (NSPoint) theLocation {
>                         mouseLocation = theLocation;
>                 }
>         and has always been updated correctly as revealed by mouseDown and
> other's NSLog.

Having accessor isn't enough to make your modification of ivars that
are used by bindings. In your code that modifies mouseLocation you
either have to use your accessor ([self setMouseLocation:blah]) or
wrap modification of the ivar with calls to
willChangeValueForKey:/didChangeValueForKey.

Basically ...

- (void) mouseDown:(NSEvent *)event {
    [self setMouseLocation:[self convertPoint:[event locationInWindow]
fromView:nil]];
    [self setNeedsDisplay:YES];
}

By using your accessor you are sending the change via a pathway that
the bindings framework can detect the change. If you don't do that
then you need to do something like the following...

- (void) mouseDown:(NSEvent *)event {
    [self willChangeValueForKey:@"mouseLocation"];
    mouseLocation = [self convertPoint:[event locationInWindow] fromView:nil];
    [self didChangeValueForKey:@"mouseLocation"];

    [self setNeedsDisplay:YES];
}

Review... <http://developer.apple.com/documentation/Cocoa/Conceptual/KeyValueObserving/Concepts/AutoVsManual.html#//apple_ref/doc/uid/20001844-BAJEAIEE>
 _______________________________________________
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: Stuck in basic bindings
      • From: Francis Derive <email@hidden>
References: 
 >Stuck in basic bindings (From: Francis Derive <email@hidden>)
 >Re: Stuck in basic bindings (From: Miguel Sanchez <email@hidden>)
 >Re: Stuck in basic bindings (From: Francis Derive <email@hidden>)
 >Re: Stuck in basic bindings (From: Camillo Lugaresi <email@hidden>)
 >Re: Stuck in basic bindings (From: Francis Derive <email@hidden>)

  • Prev by Date: Re: New titanium interface available to Cocoa developers?
  • Next by Date: CORE DATA: derived values from several entities and managed object instances ??
  • Previous by thread: Re: Stuck in basic bindings
  • Next by thread: Re: Stuck in basic bindings
  • Index(es):
    • Date
    • Thread