Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 特定于应用程序的UIPasteboard_Ios_Objective C_Cocoa Touch_Uikit_Uipasteboard - Fatal编程技术网

Ios 特定于应用程序的UIPasteboard

Ios 特定于应用程序的UIPasteboard,ios,objective-c,cocoa-touch,uikit,uipasteboard,Ios,Objective C,Cocoa Touch,Uikit,Uipasteboard,我正在尝试创建特定于应用程序的UIPasteboard,但在确定如何注册时遇到一些问题: UIPasteboard *pasteboard = [UIPasteboard pasteboardWithName:@"myPasteboard" create:YES]; 若我只是创建它,那个么应用程序将继续使用generalPasteboard。我真的希望我不必捕捉剪切/复制/粘贴操作并手动设置项目 //Copy your text field text and Just App in Paste

我正在尝试创建特定于应用程序的UIPasteboard,但在确定如何注册时遇到一些问题:

UIPasteboard *pasteboard = [UIPasteboard pasteboardWithName:@"myPasteboard" create:YES];
若我只是创建它,那个么应用程序将继续使用generalPasteboard。我真的希望我不必捕捉剪切/复制/粘贴操作并手动设置项目

//Copy your text field text and Just App in Pasteboard
NSString * text=textfield.text;
UIPasteboard * pasteboard=[UIPasteboard generalPasteboard];
[pasteboard setString:text];
下面是关于粘贴板的教程。 请阅读这篇文章 (它是关于UILabel的,而不是UITextField,但仅用于示例和有关复制/粘贴/编辑操作如何工作以及如何自定义其行为的信息)

例如,我认为您需要将
UITextField
子类化为
MyTextField
,并覆盖
-(void)copy:
-(void)paste:
UIResponderStandardEditActions
中的
方法

在实现这些方法时,您应该使用自定义的
UIPasteboard
将文本复制到其中并从中粘贴,如本答案中所述


但是不要使用
[UIPasteboard generalPasteboard]
而是使用
[UIPasteboard pasteboardWithName:@“myPasteboard”创建:是]

如何在pasteboard中复制和粘贴项目?我需要它来处理UITextFields。当用户选择并复制文本时。您也可以在不调用原始选择器的情况下滑动文本
//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
}