1

试图让它工作,但不确定我错过了什么。这个想法是将图像放在 a 上NSTableView,以便我可以抓住它们的路径并为它们做一些操作。我可以让 drop 工作NSPastebouardTypeString,但我一辈子都不能让它注册从 Finder 拖动 PNG 到 tableview 中。我错过了什么?

相关代码:

- (void)awakeFromNib {
    [imageTableView registerForDraggedTypes:[NSArray arrayWithObject:NSPasteboardTypePNG]];
}

- (NSDragOperation)tableView:(NSTableView *)aTableView validateDrop:(id < NSDraggingInfo >)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)operation {
    NSLog(@"Validate Drop");
    return NSDragOperationEvery;
}

- (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id < NSDraggingInfo >)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation {
    NSLog(@"Accept Drop");
    return YES;
}
4

1 回答 1

1

从 Finder 中拖出的PNG文件不是PNG 数据。它们是文件,它们有自己的粘贴板类型。(作为文件,您不一定希望它们在丢失的情况下完全加载到内存中,对吗?:D)

10.4 给了你一个 NSStrings 的 NSArray 作为NSFilenamesPboardType. 10.5 及更高版本为您提供了一个文件数组: URL 为NSURLPboardType. 由于您使用的是较旧的 API,因此适用于 10.5- API 的本文档(10.6 对粘贴板 API 进行了彻底检查,使其行为更像 iOS 的 API)。

于 2010-08-05T08:58:36.737 回答