Drag and Drop in NSCollectionView Example

I need to drag to NSCollectionView.

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

There is a drag and drop method. But that does not work.

I added the following method with no result:

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

The delegate is configured.

Does anyone know a solution?

+4
source share
3 answers

You need to do two things: make sure your selection is included in your NSCollectionView and implements

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

No need to implement collectionView:(NSCollectionView *)collectionView canDragItemsAtIndexes:(NSIndexSet *)indexes withEvent:(NSEvent *)event if you don't need the draggability variable. If you do not implement it, the collection view will try to start dragging and dropping for each item in the collection.

+4
source

He is already working.

You need to click, wait up to one second. After sec clicking on it drags ...

-.-

+3
source

You can simply implement drag and drop in the prototype of the collection item view. Each NSView supports drag and drop if you implement the necessary methods in your subclass.

0
source

Source: https://habr.com/ru/post/1336614/


All Articles