将UITextView复制到PasteBoard

时间:2014-12-25 15:11:34

标签: clipboard uipasteboard pasteboard

我正在尝试将“DescriptionLabel”复制到粘贴板。 DescriptionLabel被设置为UITextView(我知道这个名字有点令人困惑......)。无论如何,

- (IBAction)copy:(id)sender {

    UIPasteboard *appPasteBoard = [UIPasteboard generalPasteboard];
    appPasteBoard.persistent = YES;
    [appPasteBoard setString:@"This text is being copied"];
    }

正在复制代码中的字符串,但我无法让它复制我的UITextView / DescriptionLabel。这个:

[appPasteBoard setString:_DescriptionLabel];

无效。

你们是否有任何关于我能做些什么才能让它发挥作用的线索?几天来一直在努力......

1 个答案:

答案 0 :(得分:1)

嗯,问题是您使用setString:在粘贴板中存储UITextView,它是一个UIKit控件而不是NSString。您可能的意思是存储其文本值。

Objective-C不支持Scala或Swift等隐式转换。解决方案很简单,只需显式访问text属性:

[appPasteBoard setString:_DescriptionLabel.text];

我建议您查看UIPasteboard文档,了解有关API的详细信息:https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIPasteboard_Class/index.html