Paste from unique PasteBoard (app-specific pasteboard)

旧时模样 提交于 2019-12-12 02:35:35

问题


Im Saving to a unique pasteboard here:

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

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

Trying to read it out here:

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

   _myTextFieldHere.text = [pasteSaved string];

My error is "no class method for selector" for my local variable of pastesaved

What ive tried so far

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

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

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

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

 UIPasteboard *pasteSaved = [UIPasteboard pasteboardWithUniqueName];  

回答1:


Fixed it

It appears than when using a app specific pasteboard you need to add if your creating a pasteboard or receiving from it using create YES or No

Copy to Pasteboard

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

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

Paste from Pasteboard

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

   self.myTextFieldHere.text = [pasteboard string];



回答2:


After you have created your unique pasteboard, you paste items to it using the addItems: method:

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

Alternatively,

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

EDIT:

To read from the pasteboard:

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


来源:https://stackoverflow.com/questions/19606920/paste-from-unique-pasteboard-app-specific-pasteboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!