我正在尝试从我的应用程序中的NSOutlineView拖放到其他应用程序(.mid MIDI文件),它正在工作。我可以将它们拖到Reaper(DAW)中,然后将它拖到Finder中。但是当尝试像Presonus Studio One这样的其他应用程序时,它会在不显示加号的情况下拒绝它。如果我将同一个文件直接从Finder拖到Studio One,那么Studio One正在接受该文件,但不是来自我的应用程序。
我的代码应该可以工作,因为可以将文件拖到Finder和Reaper。
为什么这不起作用?我现在很困惑..
这是我的代码:
// The interface
@interface OutlineViewController : NSObject <NSOutlineViewDataSource, NSOutlineViewDelegate, NSDraggingDestination>...
@implementation OutlineViewController
- (id)init
{
self = [super init];
if (self)
{
// I have tried to call this from awakeFromNib but no difference
[self insertAll];
}
return self;
}
- (void)awakeFromNib
{
[super awakeFromNib];
}
- (void) insertAll
{
[_outlineView registerForDraggedTypes:[NSArray arrayWithObjects:LOCAL_REORDER_PASTEBOARD_TYPE, NSStringPboardType, NSFilenamesPboardType, nil]];
[_outlineView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:NO];
[_outlineView setAutoresizesOutlineColumn:NO];
// HERE it will insert all lines to the outline view and it is working...
}
- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
{
return !item?[_people count]:[[item child] count];
}
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
{
return !item?YES:[[item child] count] != 0;
}
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
{
return !item?[_people objectAtIndex:index]:[[item child] objectAtIndex:index];
}
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
{
if ([[tableColumn identifier] isEqualToString:@"name"])
{
return [item name];
}
else if ([[tableColumn identifier] isEqualToString:@"parentName"])
{
return [item parentName];
}
return @"";
}
- (id<NSPasteboardWriting>)outlineView:(NSOutlineView *)outlineView pasteboardWriterForItem:(id)item
{
// This is returning a valid NSUrl like
// file://localhost/Users/Me/File.mid on a drag
// everything's working to Reaper and Finder
return (id <NSPasteboardWriting>)[item fileURL];
}