gpt4 book ai didi

objective-c - 获取 NSTableView 以注册 PNG 源中的 drop

转载 作者:行者123 更新时间:2023-12-03 17:17:13 25 4
gpt4 key购买 nike

试图让它发挥作用,但不确定我错过了什么。这个想法是将图像放在 NSTableView 上,以便我可以抓取它们的路径并为它们做一些操作。我可以让拖放为 NSPastebouardTypeString 工作,但我一生都无法让它注册将 PNG 从 Finder 拖到表格 View 中。我错过了什么?

相关代码:

- (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;
}

最佳答案

从 Finder 拖动的

PNG 文件不是 PNG 数据。它们是文件,有自己的粘贴板类型。 (作为文件,您不一定希望它们在掉落时完全加载到内存中,不是吗?:D)

10.4 为您提供了一个 NSString 的 NSArray 作为 NSFilenamesPboardType。 10.5 及更高版本为您提供了一组 file: URL 作为 NSURLPboardType。由于您使用的是较旧的 API,this document on 10.5- APIs applies (10.6 彻底修改了粘贴板 API,使其行为更像 iOS 的 API)。

关于objective-c - 获取 NSTableView 以注册 PNG 源中的 drop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3406254/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com