Drag String data from My Cocoa App to Third-Party Cocoa App
- by Woodster
Hello,
I want to drag a row from my tableview and drop it into any other NSTextField in Mac OS X 10.6, and have a string of text be dropped.
Drag and drop already works within my app (between a NSTableView and an NSBrowser), but I have had no success putting any data on the pasteboard that can accepted by apps other than the source application.
Here's the code I tried, which I thought would be enough to get hte word "hello" to be 'pasted' when I drop into some other NSTextField:
-(BOOL) tableView:(NSTableView *)tableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard {
[pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:self];
[pboard setString:@"hello" forType:NSStringPboardType];
return YES;
}
//--
I never get the cursor that shows me the drop will be accepted, and it just doesn't work.
Things I've tried:
Using the 10.5 version of the Pasteboard identifier,
NSStringPBoardType
Using the 10.6 version, NSPasteboardTypeString.
Setting the owner = nil, since I'm not providing the data lazily.
Using the keyed archiver: [pboard setData:[NSKeyedArchiver archivedRootObject:@"Hello!!"]]
None of the above have worked. I think I have the concepts correct: "Encode data, tell the pasteboard what you've got, then give it the data", but since other apps don't recognize it, I suspect I'm not telling the pasteboard the correct datatype.
Where am I going wrong?
Thanks,
Woody