0

I want to create an application with this functionality, it's simple: When click down the mouse a button I want to change the text of a label and when I click up to change again this label text.

Can you help me, please? Dont know how to do

I did this:

#import "MyButton.h"

@implementation MyButton

- (void)mouseDown:(NSEvent *)event
{
    NSLog(@"down");
}

- (void)mouseUp:(NSEvent *)event
{
    NSLog(@"up");  
}

and it works, but when I want to handle the events, nothing happens

Thanks

esqew
  • 42,425
  • 27
  • 92
  • 132

1 Answers1

0

Assuming you already have your NSTextField hooked up to an IBOutlet named label:

- (void)mouseDown:(NSEvent *)event
{
     [label setStringValue:@"hi"];
}

- (void)mouseUp:(NSEvent *)event
{
     [label setStringValue:@"bye"];
}
esqew
  • 42,425
  • 27
  • 92
  • 132
  • Where should I do this? I've tried but it doesn't work. I might explain bad what I want to do: I want to press a button (click down) and capture that event, showing a message in a label for example. And when I unpress the button (click up), capture that event to. Showing another message – user3204726 Jan 17 '14 at 17:24
  • In your `NSButton` subclass as you have set up. – esqew Jan 17 '14 at 20:32
  • And how do I link/connect that label (which is in MainMenu.xib) to my subclass? – user3204726 Jan 18 '14 at 19:02