Reputation: 3121
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
Reputation: 9528
NSClickGestureRecognizer *click = [[NSClickGestureRecognizer alloc] initWithTarget:self action:@selector(myTextFieldClicked:)];
[self.myTextField addGestureRecognizer:click];
Upvotes: 18
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
Reputation: 516
The method you are looking for is - textShouldBeginEditing:
You have to set the delegate of the NSTextField, first of all.
Upvotes: -4