Drag a file from NSTableView to another osx application

I want to drag a file from an NSTableView line to copy it to another application (i.e., Finder). I followed the first two steps ("Customizing the table view", "Starting a drag operation") of this guide and thought it would do the trick: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/TableView /Tasks/UsingDragAndDrop.html

However, when I try to drag a line, the text of the line follows my mouse, but the file is not copied when released. Here is what I send to the UITableView on initialization:

#define librarySongDataType @"NSFileContentsPboardType"
- (void)awakeFromNib
{
    [self setDraggingSourceOperationMask:NSUIntegerMax forLocal:YES]; // allow interapplication drags
    [self registerForDraggedTypes:[NSArray arrayWithObject:librarySongDataType] ]; // NSFileContentsPboardType
}

Here's how I handle drag and drop in an NSTableView (NSArrayController) data source:

- (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard
{
    NSLog(@"writeRowsWithIndexes");
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:rowIndexes];
    [pboard setData:data forType:librarySongDataType];
    return YES;
}

, , .

+3
1

-, , ?

 [self setDraggingSourceOperationMask:NSUIntegerMax forLocal:YES]; 

. NSUIntegerMax. , . , NSUIntegerMax , ; Apple . NSDragOperationCopy - . - , /-.

-, forLocal: NO ; local .

-, ,

 [pboard setData:data forType:librarySongDataType];

NSFileWrapper writeFileWrapper:, . . , Finder. , .

+10

Source: https://habr.com/ru/post/1778065/


All Articles