如何實現NSOutlineViewDataSource
拖拽Finder時拖拽文件系統中不存在的目錄?我已經搜索和搜索並閱讀了大量的文檔,但很難找到有用的任何有價值的東西。我使用管理類文件系統樹的自定義數據源,並且所有項目都是跟蹤其路徑的類的實例。我想能夠將文件和目錄拖出大綱視圖到Finder中。NSOutlineView拖拽目錄
我:
- (BOOL)outlineView:(NSOutlineView *)outlineView
writeItems:(NSArray *)items
toPasteboard:(NSPasteboard *)pasteboard
{
NSMutableArray *types = [NSMutableArray array];
for (JOItemInfo *itemInfo in items) {
NSString *extension = itemInfo.name.pathExtension;
if (extension.length > 0) [types addObject:extension];
}
[pasteboard declareTypes:@[(__bridge_transfer NSString *)kPasteboardTypeFileURLPromise]
owner:self];
[pasteboard setPropertyList:types
forType:(__bridge_transfer NSString *)kPasteboardTypeFileURLPromise];
DDLogInfo(@"Wrote types %@ to pasteboard %@ for key %@",
types,
pasteboard,
(__bridge_transfer NSString *)kPasteboardTypeFileURLPromise);
return YES;
}
,並寫入給定的通道里面的物品的-outlineView:namesOfPromisedFilesDroppedAtDestination:forDraggedItems:
的實現。這樣做的作用在於我可以將項目拖出到Finder,但是當我放開時沒有其他任何事情發生,並且-...namesOfPromisedFilesDropped...
方法甚至沒有被調用。此外,
[self.outlineView setDraggingDestinationFeedbackStyle:NSTableViewDraggingDestinationFeedbackStyleRegular];
[self.outlineView setDraggingSourceOperationMask:NSDragOperationNone forLocal:YES];
[self.outlineView setDraggingSourceOperationMask:NSDragOperationCopy forLocal:NO];
是在我的-awakeFromNib
。 if (extension.length > 0) ...
是基於我在某處找到的一個示例,但是它的日期和文檔說要返回一個擴展名,所以我認爲這是適當的。就我個人而言,我發現這個整個地區的文件非常缺乏,特別是關於NSOutlineView
。謝謝!