我的项目中有短信回复屏幕,与什么应用程序相同。屏幕包含消息气泡和“文本视图”,用于输入用户想要发送的消息和发送按钮。我正在尝试编写代码以使复制/粘贴消息气泡与什么应用程序相同。我在网上看到了一个名为“可复制单元格”的演示代码,它使用长按手势来复制表格视图单元格的内容。当我试图复制消息气泡时,该单元格成为第一响应者,并且“文本视图”辞职响应者,因为该键盘是隐藏的。所以当键盘可见时我无法复制消息气泡。我也尝试过使用其他临时文本字段,但它不起作用。我想要适用于 iOS5、6 和 7 的解决方案。请帮忙。谢谢你。
问问题
866 次
1 回答
0
@interface TestViewController ()
@property (strong, nonatomic) UITextView *textView;
@end
@implementation TestViewController
- (void)copyAction {
/* Copies the string from the textView into the UIPasteBoard */
UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
pasteBoard.persistent = YES;
[appPasteBoard setString:self.textView.text];
}
- (NSString *)stringInPasteBoard {
/* Returns the string in the UIPasteBoard if any */
UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
if([pasteBoard string] != NULL && [pasteBoard string].length > 0)
return [pasteBoard string];
return nil;
}
@end
于 2013-09-24T13:36:14.127 回答