Mar*_*fer 9 iphone copy-paste iphone-sdk-3.0 uipasteboard
尝试将多个数据表示放在iPhone 3.0上的粘贴板上时遇到了一些问题.
我要做的是将数据表示和字符串表示放在粘贴板上.数据是我自己的数据类型,我用它来复制和粘贴我的应用程序.字符串表示是一种将我的应用程序内容作为大纲复制并粘贴到其他应用程序(例如Mail.app)的方法.
// payload
NSString *pasteboardString = [selectedNode stringRepresentation];
NSDictionary *pasteboardDictionary = [selectedNode nodeAndSubnodesProperties];
// set payload
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = pasteboardString;
[pasteboard setValue:pasteboardDictionary forPasteboardType:MNTNodesPasteboardType];
Run Code Online (Sandbox Code Playgroud)
上面的代码不起作用,因为string属性和setValue:forPasteboardType:methode替换了粘贴板上的第一个表示.我尝试了addItems:但它对我不起作用.
感谢您的任何帮助!
Mar*_*fer 16
回答我自己的问题:
您必须使用items属性将多个表示放入粘贴板.为此,您需要创建一个字典,其中每个表示作为值,表示类型作为键.将此字典添加到数组中,其中数组中的每个项目表示一个项目(UIPasteboard支持向粘贴板添加多个项目以及向每个项目添加多个表示).
具有两个表示的单个项的示例代码:
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSMutableDictionary *item = [NSMutableDictionary dictionaryWithCapacity:2];
[item setValue:[NSKeyedArchiver archivedDataWithRootObject:pasteboardDictionary] forKey:MNTNodesPasteboardType];
[item setValue:pasteboardString forKey:(NSString *)kUTTypeUTF8PlainText];
pasteboard.items = [NSArray arrayWithObject:item];
Run Code Online (Sandbox Code Playgroud)
不要忘记链接MobileCoreServices框架来解析UTI常量.
| 归档时间: |
|
| 查看次数: |
5392 次 |
| 最近记录: |