从唯一的PasteBoard(特定于应用程序的粘贴板)粘贴

时间:2013-10-26 12:50:46

标签: ios objective-c cocoa-touch uipasteboard

我在这里保存到唯一粘贴板:

UIPasteboard *pasteboard = [UIPasteboard pasteboardWithName:@"myPasteboard" create:YES];
[pasteboard setPersistent:YES];

//save to unique pasteboard
[pasteboard setString: [NSString stringWithFormat:@"%@",self.myTextFieldHere]];

试着在这里阅读:

UIPasteboard *pasteSaved = [UIPasteboard pasteboardWithName:@"myPasteboard"];

   _myTextFieldHere.text = [pasteSaved string];

对于我的本地变量pastesaved

,我的错误是“没有选择器的类方法”

到目前为止我尝试了什么

 UIPasteboard *pasteSaved =[[UIPasteboard pasteboardTypes] containsObject:@"myPasteBoard"];

 UIPasteboard *pasteSaved = [UIPasteboard pasteboardWithName:@"myPasteboard"];

 UIPasteboard *pasteSaved = [UIPasteboard pasteboardWithUniqueName:@"myPasteboard"];

 UIPasteboard *pasteSaved = [UIPasteboard: @"myPasteboard"];

 UIPasteboard *pasteSaved = [UIPasteboard pasteboardWithUniqueName];  

2 个答案:

答案 0 :(得分:0)

创建独特的粘贴板后,使用addItems:方法将项​​目粘贴到其中:

[pasteboard addItems:@[ @"my_string_for_pasting" ]];

或者,

[[UIPasteboard pasteboardWithUniqueName:@"myPasteboard"] addItems:@[ @"my_string_for_pasting"];

修改

从粘贴板中读取:

NSString *copiedString = [[UIPasteboard pasteboardWithUniqueName:@"myPasteboard"] valueForPasteboardType:kUTTypePlainText];

答案 1 :(得分:0)

修正了它

与使用应用专用粘贴板相比,如果您使用create YES or No

创建粘贴板或从中接收粘贴板,则需要添加

复制到粘贴板

UIPasteboard *pasteboard = [UIPasteboard pasteboardWithName:@"myPasteboard" create:YES];
[pasteboard setPersistent:YES];

//save to unique pasteboard
[pasteboard setString: [NSString stringWithFormat:@"%@",self.myTextFieldHere]];

从粘贴板粘贴

 UIPasteboard *pasteboard = [UIPasteboard pasteboardWithName:@"ICPatEditionPasteboard" create:NO];

   self.myTextFieldHere.text = [pasteboard string];