在 iPhone 上复制并粘贴多种数据表示形式
当我尝试将多个数据表示放到 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];
上面的代码不起作用,因为字符串属性和 setValue:forPasteboardType: 方法替换了粘贴板上的第一个表示形式。 我尝试了 addItems: 但它对我不起作用。
感谢您的任何帮助!
I encountered some issues when trying to put more than one data representation onto the pasteboard on iPhone 3.0.
What I'm trying to do is put a data representation and a string representation onto the pasteboard. The data is my own data type and I use it for copy and paste in my application. The string representation is a way to copy and paste the content of my application as an outline into an other application (for example 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];
The above code doesn't work because the string property and setValue:forPasteboardType: methode replace the first representation on the pasteboard. I tried addItems: but it didn't work for me.
Thank you for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要回答我自己的问题:
您必须使用 items 属性将多个表示形式放置到粘贴板上。 为此,您需要创建一个字典,其中每个表示形式作为值,表示形式类型作为键。 将此字典添加到一个数组中,其中数组中的每个项目代表一个项目(UIPasteboard 支持将多个项目添加到粘贴板以及为每个项目添加多个表示)。
具有两种表示形式的单个项目的示例代码:
不要忘记链接 MobileCoreServices 框架来解析 UTI 常量。
To answer my own question:
You have to used the items property to put multiple representations onto the pasteboard. To do so you create a dictionary with each representation as the value and the representation type as the key. Add this dictionary to an array, where each item in the array represents an item (UIPasteboard supports adding multiple items to the pasteboard as well as adding mutliple representation to each item).
Example code for one single item with two representations:
Don't forget to link with the MobileCoreServices framework to resolve the UTI constant.
这就是 Swift 对我有用的东西
它将图像和文本一起粘贴到粘贴板上
this is what worked for me in Swift
it pastes both an image and text together to the pastboard