开发者

Set Text in NSTextView with NSData

开发者 https://www.devze.com 2023-01-05 17:04 出处:网络
I have an instance of NSData that I stored from a previous run of my application. I want to set an NSTextView\'s text using this data. It is RTF and I can\'t figure out how to do this. Any ideas or su

I have an instance of NSData that I stored from a previous run of my application. I want to set an NSTextView's text using this data. It is RTF and I can't figure out how to do this. Any ideas or suggestions? It needs to be done with code and not Inter开发者_JAVA技巧face Builder.

Thanks


//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 is close, but NSAttributedString needs to be initialized using

initWithRTFD: documentAttributes:
instead of
initWithRTF: documentAttributes:


You can initialize an NSAttributedString using RTF data, and the NSTextStorage owned by the NSTextView derives from NSMutableAttributedString. I think you can put the pieces together from that.


check that are you implemented any category on textfield or uiview?(any in built ui on which you implemented category) if yes then remove that category and check it again.

0

精彩评论

暂无评论...
验证码 换一张
取 消