UIPasteboard - 无法复制文本

Boz*_*Boz 6 iphone objective-c nsstring uipasteboard

此代码应将字符串复制到generalPasteboard,作为[[UIPasteboard generalPasteboard] string]对象,但该方法会导致程序终止.

- (void)copyResultToPasteboard {
    NSString *message = self.resultTextView.text;
    [UIPasteboard generalPasteboard].string = message;
    [message release];
}
Run Code Online (Sandbox Code Playgroud)

我认为这与格式有关,因为如果消息设置为文字字符串,方法可以正常工作,但是resultTextView.text只是一个NSString ...我不完全明白,任何人都可以帮忙吗?

Ada*_*ght 3

您确定resultTextView.text返回的是后备存储的副本,而不是实际NSString*用于存储数据的副本吗?查看Apple文档,它似乎只是返回内部指针(未保留)。对类正在使用的字符串调用releaseUITextView可能会导致此行为。