| Conforms to | |
| Framework | /System/Library/Frameworks/AppKit.framework |
| Availability | Available in Mac OS X v10.6 and later. |
| Declared in | NSCollectionView.h |
| Related sample code |
The NSCollectionViewDelegate protocol defines the optional methods implemented by delegates of NSCollectionView objects.
The NSCollectionViewDelegate provides support for both drag and drop, and pasteboard support to collection views.
– collectionView:canDragItemsAtIndexes:withEvent:
– collectionView:validateDrop:proposedIndex:dropOperation:
– collectionView:acceptDrop:index:dropOperation:
– collectionView:draggingImageForItemsAtIndexes:withEvent:offset:
– collectionView:namesOfPromisedFilesDroppedAtDestination:forDraggedItemsAtIndexes:
Invoked when the mouse is released over a collection view that previously allowed a drop.
- (BOOL)collectionView:(NSCollectionView *)collectionView acceptDrop:(id < NSDraggingInfo >)draggingInfo index:(NSInteger)index dropOperation:(NSCollectionViewDropOperation)dropOperation
The collection view that send the message.
An object that contains more information about this dragging operation.
The index of the proposed drop item.
The type of dragging operation.
YES if the drop operation should be accepted, otherwise NO.
This method is called when the mouse is released over a collection view that previously decied to allow a drop via the collectionView:validateDrop:proposedIndex:dropOperation: method. At this time, the delegate should incorporate the data from the dragging pasteboard and update the collection view's contents.
You must implement this method for your collection view to be a drag destination
NSCollectionView.hReturns whether the collection view can attempt to initiate a drag for the given event and items.
- (BOOL)collectionView:(NSCollectionView *)collectionView canDragItemsAtIndexes:(NSIndexSet *)indexes withEvent:(NSEvent *)event
The collection view that send the message.
The indexes of the proposed dragging items.
The mouse down event that initiated the drag.
YES if the items can attempt to initiate a drag for the specified items, otherwise NO.
If the delegate does not implement this method, the collection view will act as if it returned YES.
NSCollectionView.hSent to the delegate to allow creation of a custom image to represent collection view items during a drag operation.
- (NSImage *)collectionView:(NSCollectionView *)collectionView draggingImageForItemsAtIndexes:(NSIndexSet *)indexes withEvent:(NSEvent *)event offset:(NSPointPointer)dragImageOffset
The collection view that send the message.
The indexes of the dragging items.
The mouse down event that initiated the drag.
An in/out parameter that will initially be set to NSZeroPoint. it can be modified to reposition the returned image. A dragImageOffset of NSZeroPoint will cause the image to be centered under the mouse.
An image containing a rendering of the visible portions of the views for each item.
If the delegate does not implement this method, the collection view with return an image using draggingImageForItemsAtIndexes:withEvent:offset:. You can safely invoked draggingImageForItemsAtIndexes:withEvent:offset: on collectionView from within this method.
You do not need to implement this method for your collection view to be a drag source.
NSCollectionView.hInvoked to return an array of filenames that the receiver promises to create.
- (NSArray *)collectionView:(NSCollectionView *)collectionView namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropURL forDraggedItemsAtIndexes:(NSIndexSet *)indexes
The collection view that send the message.
The drop location where the files are created.
The indexes of the dragging items.
An array of filenames (not full paths) for the created files that the receiver promises to create.
The delegate can support file promise drags by adding NSFilesPromisePboardType to the pasteboard in collectionView:writeItemsAtIndexes:toPasteboard:.
For more information on file promise dragging, see documentation for the NSDraggingSource protocol and namesOfPromisedFilesDroppedAtDestination:.
You do not need to implement this delegate method for your collection view to be a drag source.
NSCollectionView.hInvoked to determine a valid drop target.
- (NSDragOperation)collectionView:(NSCollectionView *)collectionView validateDrop:(id < NSDraggingInfo >)draggingInfo proposedIndex:(NSInteger *)proposedDropIndex dropOperation:(NSCollectionViewDropOperation *)proposedDropOperation
The collection view that send the message.
An object containing details about this dragging operation.
The proposed drop index. This parameter is passed by-reference and can be modified retarget the drop operation.
The proposed drop operation. This parameter is passed by-reference and can be modified to change the drop operation.
A value that indicates which dragging operation the data source will perform. It must return something other than NSDragOperationNone to accept the drop
Based on the mouse position, the collection view will suggest a proposed index and drop operation. These values are in/out parameters and can be changed by the delegate to retarget the drop operation.
The collection view will propose NSCollectionViewDropOn when the dragging location is closer to the middle of the item than either of its edges. Otherwise, it will propose NSCollectionViewDropBefore. You may override this default behavior by changing proposedDropOperation or proposedDropIndex.
To receive drag messages, you must first send registerForDraggedTypes: to the collection view with the drag types you want to support.
You must implement this method for your collection view to be a drag destination.
NSCollectionView.hInvoked after it has been determined that a drag should begin, but before the drag has been started.
- (BOOL)collectionView:(NSCollectionView *)collectionView writeItemsAtIndexes:(NSIndexSet *)indexes toPasteboard:(NSPasteboard *)pasteboard
The collection view that send the message.
The indexes of the items to write to the pasteboard.
The pasteboard containing the content from the dragged items.
YES to begin the drag, otherwise NO.
To start the drag, you must first declare the pasteboard types that are supported by sending pasteboard a declareTypes:owner: method. You then place the data for the items at the specified indexes on pasteboard, and return YES from the method.
The drag image and other drag related information will be set up and provided by the view once this call returns YES.
You need to implement this method for your collection view to be a drag source.
NSCollectionView.hLast updated: 2009-11-12