Andreas Prang
Andreas Prang

Reputation: 2217

Drag and Drop in NSCollectionView example

I need drag and drop in NSCollectionView.

So I looked at Apples code-sample: https://developer.apple.com/library/mac/#samplecode/IconCollection/Introduction/Intro.html

There is a method for dragging. But it's not working.

I added the following method without result:

-(BOOL) collectionView:(NSCollectionView *)collectionView canDragItemsAtIndexes:(NSIndexSet *)indexes withEvent:(NSEvent *)event {
    return YES;
}

The Delegate is set.

Does anybody know a solution?

Upvotes: 3

Views: 4259

Answers (3)

Phillip Kast
Phillip Kast

Reputation: 61

You need to do two things: make sure your selection is turned on in your NSCollectionView, and implement

- (BOOL)collectionView:(NSCollectionView *)collectionView writeItemsAtIndexes:(NSIndexSet *)indexes toPasteboard:(NSPasteboard *)pasteboard

It's not necessary to implement collectionView:(NSCollectionView *)collectionView canDragItemsAtIndexes:(NSIndexSet *)indexes withEvent:(NSEvent *)event unless you want variable draggability. If you don't implement it, the collection view will attempt to start a drag for every item in the collection.

Upvotes: 4

user187676
user187676

Reputation:

You can just implement drag & drop in the collection item view prototype. Every NSView supports dragging if you implement the required methods in your own subclass.

Upvotes: 0

Andreas Prang
Andreas Prang

Reputation: 2217

It is already working.

You will have to click, wait up to one sec. After the sec. clicking it is dragged...

-.-

Upvotes: 3

Related Questions