2

I'm trying to create app-specific UIPasteboard, but have some problems figuring out how to register it:

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

If I just create it, app continues to use generalPasteboard. I really hope that I don't have to catch cut/copy/paste operations and set items manually.

Daniyar
  • 2,975
  • 2
  • 26
  • 39
Armands L.
  • 1,885
  • 2
  • 14
  • 18

3 Answers3

2

Please read this article http://nshipster.com/uimenucontroller/ (It's about UILabel, not UITextField but is useful just for example and information about how copy/paste/edit actions work and how you can customize its' behavior)

I think you need to subclass UITextField to MyTextField for example, and override -(void)copy: and -(void)paste: methods from UIResponderStandardEditActions.

In your implementation of these methods you should use your custom UIPasteboard to copy text into and paste from it, like mentioned in this answer,

How to do copy/paste function programmatically in iphone?

but instead of using [UIPasteboard generalPasteboard] use [UIPasteboard pasteboardWithName:@"myPasteboard" create:YES]

Community
  • 1
  • 1
Alexander Tkachenko
  • 3,221
  • 1
  • 33
  • 47
1
//Copy your text field text and Just App in Pasteboard
NSString * text=textfield.text;
UIPasteboard * pasteboard=[UIPasteboard generalPasteboard];
[pasteboard setString:text];

Below is a Tutorial about Pasteboard. http://hayageek.com/uipasteboard-example-read-write-share/

Renish Dadhaniya
  • 10,642
  • 2
  • 31
  • 56
0
//pasteboard initialization
let pasteBoard = UIPasteboard.general

// copying the content of textview to pasteboard
if(pasteBoard.hasStrings){
   pasteBoard.string = textViewPB.text
}

//pasting the content of pasteboard to textview
if(pasteBoard.hasStrings){
   textViewPB.text = pasteBoard.string
}