Re: Stuck in basic bindings
Re: Stuck in basic bindings
- Subject: Re: Stuck in basic bindings
- From: Francis Derive <email@hidden>
- Date: Thu, 19 Jan 2006 07:54:43 +0100
Dear all,
OK, I did see only but that - this morning : as you said, my
mouseDown method doesn't *use* the dear KVC mouseLocation accessors!
Many thanks to all of you for your patience.
I should soon reach what I want to achieve, and I'll tell you.
Cheers,
Francis.
On Jan 18, 2006, at 10:55 PM, Shawn Erickson wrote:
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