Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

fernandovalente

macrumors 6502
Original poster
Hey,

I'm trying to create an app that will have a NSCollectionView. I need to be to drag an item from the collection view to another app/desktop/Finder window.

I've implemented the dragging methods, but I'm struggling on this one:

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

I tried this code

Code:
[pasteboard readFileContentsType:nil toFile:location];
[pasteboard setString:str forType:NSPasteboardTypeString];

But when I drag the item to the desktop, just a text clip is copied. If I remove the second like, nothing is copied. What an I doing wrong?
 
I suggest you read the docs and guides relating to Dragging Source Protocol. You are missing several steps in this process. You have to:
  1. Declare the type of pasteboard data (in this case, file promises)
  2. Convert the string to NSData
  3. Write the NSData to the pasteboard for the declared type
(the second and third step can be done "lazily", when the pasteboard requests it)

EDIT: Oh, I think I also left out the part where your dragging source has to supply file name(s) for the recipient of the data, which is usually before step #2 above.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.