Set text to NSTextView using NSData

I have an instance of NSData that I saved from a previous run of my application. With this data, I want to set the text to NSTextView. This is RTF, and I cannot figure out how to do this. Any ideas or suggestions? This must be done using code, not the Builder interface.

thanks

+4
source share
4 answers
//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]; 
+9
source
  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 with

  initWithRTFD: documentAttributes: 
instead
  initWithRTF: documentAttributes: 
+2
source

You can initialize an NSAttributedString using RTF data, and the NSTextStorage owned by NSTextView is derived from NSMutableAttributedString. I think you can put these things together.

0
source

make sure you embed a category in a text box or uiview? (any of the built-in ui on which you implemented the category), if so, delete this category and check it again.

0
source

Source: https://habr.com/ru/post/1314511/


All Articles