Domanda

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];  
È stato utile?

Soluzione

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

Altri suggerimenti

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];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top