Re: Stuck in basic bindings
Re: Stuck in basic bindings
- Subject: Re: Stuck in basic bindings
- From: Miguel Sanchez <email@hidden>
- Date: Tue, 17 Jan 2006 10:56:11 -0800
Francis,
Note that setKeys: triggerChangeNotificationsForDependentKey: does
NOT automatically update the state of the object for you, it just
says that a change in one key should also trigger a notification that
another key changed, so that if a view is bound to your object it is
told to redisplay the value. But you have to change the value within
the code of your object.
In your mouseDown method, the second NSLog call references
mouseXlocation and mouseYlocation which are never set, so their
values will still be 0. Do you even need to declare mouseXlocation
and mouseYlocation? You can just remove those and change your NSLog
call to
NSLog(@"fdeGradientView -- mouseDown - mouseXlocation:%f
mouseYlocation:%f", [self mouseXlocation], [self mouseYlocation]);
- Miguel
On Jan 17, 2006, at 8:26 AM, Francis Derive wrote:
Bonjour la liste,
I have been working a big while ( subject = "Binding with value
transformer enigma" ) and I would appreciate some help from the list.
I have changed the architecture to make it simpler and more sound
to me, but still a problem.
From a custom palette, I get a view and I want to display the x and
y coordinates of the mouse downs, drags, and ups.
@interface fdeGradientView : NSView {
[...]
NSPoint mouseLocation;
float mouseXlocation;
float mouseYlocation;
}
It is not Core Data.
I use "Basic Accessor Methods" for mouseLocation ivar ( because
simple NSPoint type).
I no more bind from the NSPoint to a corresponding instance
variable of a tester model object.
Rather, I make immediately mouseXlocation and mouseYlocation depend
on mouseLocation :
- I declare the dependency in the view +initialize
- in the same +initialize, I expose the mouseXlocation and
mouseYlocation for binding
+ (void)initialize {
NSArray *keys = [NSArray arrayWithObjects:@"mouseLocation", nil];
[self setKeys:keys
triggerChangeNotificationsForDependentKey:@"mouseXlocation"];
[self setKeys:keys
triggerChangeNotificationsForDependentKey:@"mouseYlocation"];
[...]
[self exposeBinding:@"mouseXlocation"];
[self exposeBinding:@"mouseYlocation"];
}
In fact, I have not to go far away from the view, because it
appears that the dependent properties mouseXlocation and
mouseYlocation are not set in the view:
[Session started at 2006-01-17 16:44:58 +0100.]
2006-01-17 16:45:01.758 fdeGradientViewUser[2564]
FDGradientViewUser -- testerXlocation:0.000000
2006-01-17 16:45:01.784 fdeGradientViewUser[2564]
FDGradientViewUser -- testerXlocation:0.000000
2006-01-17 16:45:01.788 fdeGradientViewUser[2564]
FDGradientViewUser -- testerXlocation:0.000000
2006-01-17 16:45:01.808 fdeGradientViewUser[2564]
FDGradientViewUser -- testerXlocation:0.000000
2006-01-17 16:45:03.906 fdeGradientViewUser[2564] fdeGradientView
-- mouseDown - mouseLocation.x:231.000000 mouseLocation.y:74.000000
2006-01-17 16:45:03.907 fdeGradientViewUser[2564] fdeGradientView
-- mouseDown - mouseXlocation:0.000000 mouseYlocation:0.000000
<<<<<<<<<<<<<<
2006-01-17 16:45:03.974 fdeGradientViewUser[2564] fdeGradientView
-- mouseUp - mouseLocation.x:231.000000 mouseLocation.y:74.000000
2006-01-17 16:45:03.976 fdeGradientViewUser[2564] fdeGradientView
-- mouseUp - mouseXlocation:0.000000 mouseXlocation:0.000000
<<<<<<<<<<<<<<<<
with
- (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];
}
and
- (float) mouseXlocation {
return [self mouseLocation].x;
}
I thank you enormously for any progress I could make on this damned
promising binding subject.
Cheers,
Francis.
_______________________________________________
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
_______________________________________________
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