2014-12-25 32 views
-1

我试图将我的“DescriptionLabel”复制到粘贴板。 DescriptionLabel被设置为UITextView(我知道这个名字有点混乱......)。无论如何,将UITextView复制到PasteBoard

- (IBAction)copy:(id)sender { 

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

的串码被复制,但我不能设法得到它的拷贝我的UITextView/DescriptionLabel。此:

[appPasteBoard setString:_DescriptionLabel]; 

不起作用。

你们有没有任何线索我可以做些什么来使它工作?一直在努力...

+0

这有什么好做的Xcode。无论如何,粘贴板不能容纳*任意*对象。你想要'setString:_DescriptionLabel.text'来代替吗? –

回答

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