Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocoa/Obj-C - TextField to clipboard button

Got 1 UITextField and 1 button. There is text in my textfield, and when we click on the button, the text is copied to the OSX clipboard.

How can I do that? I've readed the NSPastboard Class Reference but didn't understand how to do that -simply-

Got my button defined in my AppControler.h like this:

- (IBAction)copyButton:(id)sender;

What am I supposed to write in my AppControler.m? My textfield is called "descTextField"

like image 274
Nono Avatar asked Mar 12 '11 15:03

Nono


1 Answers

- (IBAction)copyButton:(id)sender {
   NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
   [pasteBoard declareTypes:[NSArray arrayWithObjects:NSStringPboardType, nil] owner:nil];
   [pasteBoard setString: [textField stringValue] forType:NSStringPboardType];
}
like image 67
Max Avatar answered Nov 10 '22 08:11

Max