伙计们!有人知道怎么做到这一点吗?我是说:如果我想把一个字符串放到剪贴板上
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
[pboard declareTypes:[NSArray arrayWithObject:NSPasteboardTypeString] owner:self];
[pboard setString:@"aString" forType:NSPasteboardTypeString];
但是如果我想把一个文件放入剪贴板呢?我想找到一种方法来使用FixPATH作为参数,然后通过上下文菜单或CMDV,可以在查找器中粘贴我想要的文件。
有人能帮我吗?
谢谢!
最佳答案
很快将其组合在一起,但是使用cmd+v和上下文粘贴进行测试。
NSURL *object = [[NSURL alloc] initFileURLWithPath:@"/Users/username/Desktop/main.png"];
NSPasteboard *pb = [NSPasteboard generalPasteboard];
[pb clearContents];
NSArray *objectsToCopy = [[NSArray alloc] initWithObjects:object, nil];
BOOL pasted = [pb writeObjects:objectsToCopy];
if(pasted) // paste was successful
NSLog(@"pasted");
[object release];
[objectsToCopy release];
[pb release];