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?
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.
It is already working.
You will have to click, wait up to one sec. After the sec. clicking it is dragged...
-.-
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.
精彩评论