Instance Method

collectionView:writeItemsAtIndexPaths:toPasteboard:

Places the data for the drag operation on the pasteboard.

Declaration

- (BOOL)collectionView:(NSCollectionView *)collectionView writeItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths toPasteboard:(NSPasteboard *)pasteboard;

Parameters

collectionView

The collection view making the request.

indexPaths

The index paths of the items being dragged.

pasteboard

The pasteboard on which to place the drag data.

Return Value

YES if the drag operation can continue or NO if you want to refuse the drag.

Discussion

You must implement this method or the collectionView:pasteboardWriterForItemAtIndexPath: method to support drag operations. The collection view calls the collectionView:pasteboardWriterForItemAtIndexPath: method in preference to this one if both are implemented. If your app supports multi-image drag and drop, you must implement the collectionView:pasteboardWriterForItemAtIndexPath: method.

The collection view calls this method after it has determined that a drag should begin but before the drag operation has started. Your implementation of this method should do the following:

  1. Declare the pasteboard types you support using the declareTypes:owner: method of the provided pasteboard object.

  2. Write data to the pasteboard for each type you declare.

  3. Return YES from this method.

See Also

Drag and Drop Support

- collectionView:canDragItemsAtIndexPaths:withEvent:

Returns a Boolean indicating whether a drag operation involving the specified items can begin.

- collectionView:pasteboardWriterForItemAtIndexPath:

Provides the pasteboard writer for the item at the specified index path.

- collectionView:namesOfPromisedFilesDroppedAtDestination:forDraggedItemsAtIndexPaths:

Returns the names of the promised files that you created for a drag operation.

Deprecated
- collectionView:draggingImageForItemsAtIndexPaths:withEvent:offset:

Creates and returns a drag image to represent the specified items during a drag.

- collectionView:draggingSession:willBeginAtPoint:forItemsAtIndexPaths:

Notifies your delegate that a drag session is about to begin.

- collectionView:draggingSession:endedAtPoint:dragOperation:

Notifies your delegate that a drag session ended.

- collectionView:updateDraggingItemsForDrag:

Asks your delegate to update the dragging items during a drag operation.

- collectionView:validateDrop:proposedIndexPath:dropOperation:

Validates whether a drop operation is possible at the specified location.

- collectionView:acceptDrop:indexPath:dropOperation:

Incorporates the dropped content into the collection view.