Instance Method

collectionView:itemsForBeginningDragSession:atIndexPath:

Provides the initial set of items (if any) to drag.

Required.

Declaration

- (NSArray<UIDragItem *> *)collectionView:(UICollectionView *)collectionView itemsForBeginningDragSession:(id<UIDragSession>)session atIndexPath:(NSIndexPath *)indexPath;

Parameters

collectionView

The collection view from which the drag operation is originating.

session

The current drag session object.

indexPath

The index path of the item to drag.

Return Value

An array of UIDragItem objects containing the details of the items to drag. Return an empty array to prevent the item from being dragged.

Discussion

You must implement this method to allow the dragging of items from your collection view. In your implementation, create one or more UIDragItem objects for the item at the specified indexPath. Normally, you return only one drag item, but if the specified item has children or cannot be dragged without one or more associated items, include those items as well.

The collection view calls this method one or more times when a new drag begins within its bounds. Specifically, if the user begins the drag from a selected item, the collection view calls this method once for each item that is part of the selection. If the user begins the drag from an unselected item, the collection view calls the method only once for that item.

See Also

Providing the Items to Drag

- collectionView:itemsForAddingToDragSession:atIndexPath:point:

Adds the specified items to an existing drag session.