【发布时间】:2018-08-01 18:49:12
【问题描述】:
我需要获取 NSPasteboard 的对象并将其存储在某处,以便稍后将其放回剪贴板。我现在只使用 text 属性执行此操作。我想知道如何对任何对象执行此操作(例如:复制文件)。 到目前为止,这是我获取文本并将其放回原处的代码:
NSString *pasteboardString;
//Save the value of the pasteboard
NSPasteboard *pasteboard= [NSPasteboard generalPasteboard];
pasteboardString= [pasteboard stringForType:NSStringPboardType];
//Clear the pasteboard
[pasteboard clearContents];
//Do some stuff with clipboard
//Write the old object back
if(pasteboardString!= NULL || pasteboardString.length != 0){
[pasteboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
[pasteboard setString:pasteboardString forType:NSStringPboardType];
}
【问题讨论】:
-
您是否尝试过获取所有对象?
-
不,根本没有文档,苹果网站也无济于事。你为什么认为我在这里?
-
NSPasteboard。获取
types,读取数据:dataForType:,写入数据setData:forType:。承诺将是一个问题。隐藏在档案中:Pasteboard Programming Guide. -
谢谢,我很幸运找到了解决方案,就像你说的那样。
标签: objective-c macos clipboard nspasteboard