How do I enable drag drop of a file onto a NSTextField ?
I thought when I drop a file from filesystem to a NSTextField in my app, the path to the file is automatically written in the field.
Instead I can't drop it, and the field remains empty.
I've added this line:
[myTextField registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, nil]];
but it doesn't work.
I couldn't find any drag&drop related method in the delegates: NSControlTextEditingDelegate
or NSTextFieldDelegate
.
Thanks
You will need to subclass the NSTextField
and override the -performDragOperation:
method. Apple has several examples of how to handle dropped files in their Drag and Drop Programming Topics .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.