从独特的PasteBoard(特定于应用程序的粘贴板)
进出口保存到一个独特的粘贴板:
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];
我的错误是“没有select器的类方法”我的本地variablespastesaved
到目前为止,还没有尝试过
UIPasteboard *pasteSaved =[[UIPasteboard pasteboardTypes] containsObject:@"myPasteBoard"]; UIPasteboard *pasteSaved = [UIPasteboard pasteboardWithName:@"myPasteboard"]; UIPasteboard *pasteSaved = [UIPasteboard pasteboardWithUniqueName:@"myPasteboard"]; UIPasteboard *pasteSaved = [UIPasteboard: @"myPasteboard"]; UIPasteboard *pasteSaved = [UIPasteboard pasteboardWithUniqueName];
修复
如果您使用create YES or No
来create YES or No
粘贴板或从其接收数据,则会出现比使用特定于应用程序的粘贴板时更需要添加的function
复制到粘贴板
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];
在创build了独特的粘贴板之后,使用addItems:
方法将项粘贴到它addItems:
:
[pasteboard addItems:@[ @"my_string_for_pasting" ]];
或者,
[[UIPasteboard pasteboardWithUniqueName:@"myPasteboard"] addItems:@[ @"my_string_for_pasting"];
编辑:
从纸板读取:
NSString *copiedString = [[UIPasteboard pasteboardWithUniqueName:@"myPasteboard"] valueForPasteboardType:kUTTypePlainText];