I create a easy application. I create one class for show the coordinate from mouse.
my .m file
#import <Cocoa/Cocoa.h>
@interface MousePossition : NSView{
IBOutlet NSTextField *coordinateLabel;
NSPoint mouseLocation;
}
@end
and my .h
#import "MousePossition.h"
@implementation MousePossition
- (void)mouseDown:(NSEvent *)theEvent{
// Enregistrement des coordonées dans mouseLocation
mouseLocation = [theEvent locationInWindow];
[self updateCoordonateLabel];
// Vérification de l'exécution
NSLog(@"Clicked %f %f",mouseLocation.x,mouseLocation.y);
}
-(void)updateCoordonateLabel
{
NSString *a = [NSString stringWithFormat:@"X : %f\n X : %f", mouseLocation.x, mouseLocation.y];
// MàJ du Label avec les coordonées
[coordinateLabel setStringValue:a];
NSLog(@"%@", a);
}
@end
But the label don't update after click on my mouse! Any idea what is the problem?
If I create a button and convert -(void)updateCoordonateLabel
to -(IBAction)updateCoordonateLabel:(id)sender
the label show always 0.0000 on x and y