views:

59

answers:

3

I have an NSArrayController that I'm using to provide data to an IKImageBrowserView. I want to support drag and drop from the IKImageBrowserView to other applications. Here's the relevant method from my code:

- (NSUInteger) imageBrowser:(IKImageBrowserView *) aBrowser writeItemsAtIndexes:(NSIndexSet *) itemIndexes toPasteboard:(NSPasteboard *)pasteboard{
    NSArray *items = [[resultsArrayController arrangedObjects] objectsAtIndexes:itemIndexes];
    if(![pasteboard writeObjects:items]){
        return 0;
    }
    return [items count];
}

My app is new so I'm targeting 10.6+ and according to the documentation, "On Mac OS X v10.6 and later, use writeObjects: to write URLs directly to the pasteboard instead."

I've verified that the objects that I am attempting to write are indeed NSURL objects, so I'm not sure where the process is breaking down or how to further troubleshoot the problem. Thanks in advance for any help.

A: 

Have you verified that your pasteboard variable is not nil?

JWWalker
Hadn't before and it was a good thought, but alas, no dice. It's not nil. :( Related: Why can't Cocoa have whiny nils like Ruby?
jxpx777
A: 

Are the objects that are to be sent to -[NSPasteboard writeObjects:] supposed to be NSPasteboadItems? You can set their string value to the absoluteString of the NSURL and write an array of NSPasteboadItems.

mj1531
See http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSPasteboard_Class/Reference/Reference.html%23//apple_ref/occ/instm/NSPasteboard/writeObjects: . Any objects that conform to the `NSPasteboardWriting` protocol are acceptable, and NSURL objects (when AppKit is present) do conform to this protocol.
Peter Hosey
+2  A: 

Have you cleared the pasteboard yet? You need to do that, and thereby become the pasteboard's owner, before you can write objects to the pasteboard.

Peter Hosey
Thanks, Peter. That was it exactly. Adding that to my toolbar of technicalities to remember. :)
jxpx777