Introduction to Drag and Drop
Explains how to implement drag and drop in Cocoa.
Organization of This Document
In the text here and in the dragging protocol descriptions, the term dragging session is the entire process during which an image is selected, dragged, released, and absorbed or rejected by the destination. A dragging operation is the action that the destination takes in absorbing the image when it is released. The dragging source is the object that “owns” the image that is being dragged; it is specified as an argument to the method that instigates the dragging session.
Dragging is a visual phenomenon. To be the source or destination of a dragging operation, an object must represent a portion of screen real estate; thus, only window and view objects can be the sources and destinations of drags. (Note that the source view is not necessarily the same objects as the dragging source defined above.) NSWindow and NSView provide methods that handle the user interface for dragging an object. You only need to implement a few methods from either the NSDraggingSource or NSDraggingDestination protocol, depending on whether your window or view subclass is the source or destination.
The dragging protocols are described in these articles:
Dragging Sources
Dragging Destinations
How to receive a drag is described in these articles:
Receiving Drag Operations
Dragging Files
Commonly-asked questions about drag-and-drop are addressed in this article:
Frequently Asked Questions
Next
Copyright © 2012 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2012-01-09