macoscocoanstextfield

Detect paste on NSTextField


I'm trying to handle a paste operation on a NSTextField.

I found a similar article but for NSTextView. I tried code similar to this by overriding NSTextField and putting:

- (BOOL)readSelectionFromPasteboard:(NSPasteboard *)pboard
{
    return [super readSelectionFromPasteboard: pboard];
}

But this method seems to never be called.

Any suggestions on how to detect a past on NSTextField?


Solution

  • You could use the NSTextFieldDelegate delegate method - (BOOL) control:(NSControl*) control textView:(NSTextView*) textView doCommandBySelector:(SEL) commandSelector and watch for the paste: selector.