Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
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.

Thanks!
 
How about this?

https://developer.apple.com/library...ngs/CocoaDragAndDrop_DragDropImageView_m.html

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:

Code:
- (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:

https://developer.apple.com/library...Destination_Protocol/Reference/Reference.html
 
Last edited:
Thanks, I will begin to work my way though that tutorial.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.