2

Could someone nudge me in the right direction on this. I want to drag a NSString from a table cell to a NSView and then do something based on that string but the drag and drop stuff has my head spinning a bit. Anyway know of a straight forward tutorial that can explain all this.

Thanks

PruitIgoe
  • 6,166
  • 16
  • 70
  • 137

1 Answers1

5

The table view data source has a method for starting a drag operation. Here's a little code to start the dragging:

- (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard
{
    NSString *myString = ...; // code to get a string from the indexes in rowIndexes
    return [pboard setString:myString forType:NSPasteboardTypeString];
}

For receiving drag operations, I think there has been enough written about it: This is an older tutorial (2002), but I think it should still be valid. Just be sure to check the documentation about deprecated methods/names (or look at the compiler warnings): http://cocoadevcentral.com/articles/000056.php

Apples drag and drop programming guide

Or this stack overflow question with links to sample code: Cocoa multi window drag and drop example

Community
  • 1
  • 1
Michael
  • 447
  • 3
  • 10