Objective c UIPasteboard-无法复制文本

Objective c UIPasteboard-无法复制文本,objective-c,iphone,nsstring,uipasteboard,Objective C,Iphone,Nsstring,Uipasteboard,此代码应将字符串作为[[UIPasteboard generalPasteboard]string]对象复制到generalPasteboard,但该方法会导致程序终止 - (void)copyResultToPasteboard { NSString *message = self.resultTextView.text; [UIPasteboard generalPasteboard].string = message; [message release]; } 我

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

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

我认为这与格式有关,因为如果消息设置为文本字符串,则该方法可以工作,但resultTextView.text只是一个NSString。。。我不太明白,有人能帮忙吗?

您确定
resultTextView.text
返回的是备份存储的副本,而不是用于存储数据的实际
NSString*
?查看苹果的文档,似乎只是返回了内部指针(未恢复)。对
UITextView
类正在使用的字符串调用release可能会导致此行为。

您正在向一个对象发送
-release
,而该对象您没有(或者至少,从snippit上看,您没有)首先
-retain
+alloc
或者通过
-copy
复制另一个对象