Drag and Drop tutorials

Discussion in 'Mac Programming' started by larswik, Jun 30, 2014.

  1. larswik macrumors 68000

    Sep 8, 2006
    I am looking to find any tutorial for dragging a text file and dropping it on an NSTextField. Then have the contents of the .txt file populate the NSTextField. I have found lots of youtube videos for drag/drop images to a UIImageView but nothing for text.

  2. ArtOfWarfare, Jun 30, 2014
    Last edited: Jun 30, 2014

    ArtOfWarfare macrumors G3


    Nov 26, 2007
    How about this?


    It says that it specifically uses images but can be expanded to other datatypes as well.

    It looks like the important part is to have your view class conform to NSDraggingDestination, with a method like this:

    - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
        NSURL* fileURL = [NSURL URLFromPasteboard:[sender draggingPasteboard]];
        // ... load the contents of the file that is pointed to by the URL into the text view.
        return YES;
    There's a few other methods it looks like you might need to implement, too, to fully conform to NSDraggingDestination. See the reference for the protocol here:

  3. larswik thread starter macrumors 68000

    Sep 8, 2006
    Thanks, I will begin to work my way though that tutorial.

Share This Page