[英]Set Text in NSTextView with NSData
我有一個NSData實例,我從之前的應用程序運行中存儲。 我想使用這些數據設置NSTextView的文本。 它是RTF,我無法弄清楚如何做到這一點。 任何想法或建議? 它需要使用代碼而不是Interface Builder。
謝謝
//First convert a NSData object to a NSString object.
NSData *aData;
//assign aData to what you want it to.
NSAttributedString *aStr;
aStr = [[[NSAttributedString alloc] initWithRTF:aData documentAttributes:NULL] autorelease];
//then set the textView to that value.
[[yourTextView textStorage] setAttributedString:aStr];
NSData *myData; // RTF data NSAttributedString *myString = [[NSAttributedString alloc] initWithRTFD:myData documentAttributes:NULL]; [[yourTextView textStorage] setAttributedString:myString];
thyrgle很接近,但NSAttributedString需要使用初始化
initWithRTFD: documentAttributes:代替
initWithRTF:documentAttributes:
您可以使用RTF數據初始化NSAttributedString,NSTextView擁有的NSTextStorage來自NSMutableAttributedString。 我想你可以把它們拼湊起來。
檢查你是否在textfield或uiview上實現了任何類別?(在你實現類別的任何內置ui中)如果是,則刪除該類別並再次檢查。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.