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
NSTextFieldand override the-performDragOperation:method. Apple has several examples of how to handle dropped files in their Drag and Drop Programming Topics.