Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding click action to NSTextField

Tags:

How do I attach a event to a NSTextField for when I click on it? Are there any examples out there?

like image 228
AdamB Avatar asked Apr 07 '11 21:04

AdamB


2 Answers

NSClickGestureRecognizer *click = [[NSClickGestureRecognizer alloc] initWithTarget:self action:@selector(myTextFieldClicked:)];
[self.myTextField addGestureRecognizer:click];
like image 195
John Erck Avatar answered Nov 17 '22 01:11

John Erck


You can try this: It works for me.

    @interface customTextField : NSTextField
    @property (strong) id target;
    @end

    @implementation customTextField

    - (void)mouseDown:(NSEvent *)theEvent
    {
        [self sendAction:@selector(clickAction:) to:[self target]];
    }

    @end

Thanks.

like image 25
Neelam Verma Avatar answered Nov 16 '22 23:11

Neelam Verma