AdamB
AdamB

Reputation: 3121

adding click action to NSTextField

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

Upvotes: 23

Views: 11886

Answers (3)

John Erck
John Erck

Reputation: 9528

NSClickGestureRecognizer *click = [[NSClickGestureRecognizer alloc] initWithTarget:self action:@selector(myTextFieldClicked:)];
[self.myTextField addGestureRecognizer:click];

Upvotes: 18

Neelam Verma
Neelam Verma

Reputation: 3274

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.

Upvotes: 7

saimonx
saimonx

Reputation: 516

The method you are looking for is - textShouldBeginEditing:

You have to set the delegate of the NSTextField, first of all.

Upvotes: -4

Related Questions