Copy and Paste on iPhone with multiple data representations

后端 未结 1 1380
执念已碎
执念已碎 2021-02-14 20:42

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

相关标签:
1条回答
  • 2021-02-14 21:38

    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:

        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];
    

    Don't forget to link with the MobileCoreServices framework to resolve the UTI constant.

    0 讨论(0)
提交回复
热议问题