开发者

Drag and Drop in NSCollectionView example

开发者 https://www.devze.com 2023-02-05 23:38 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消