Re: NSTextView with RTF as string?
Re: NSTextView with RTF as string?
- Subject: Re: NSTextView with RTF as string?
- From: Nicko van Someren <email@hidden>
- Date: Fri, 6 May 2005 14:04:22 +0100
On 6 May 2005, at 13:32, John Timmer wrote:
I've got some RTF that I've generated manipulating a string's contents
in code. I need to put that into a Text View. If I try the
following:
[rtfText writeToFile: [@"~/Desktop/blurk.rtf"
stringByExpandingTildeInPath] atomically: YES];
[textView replaceCharactersInRange: NSMakeRange(0,0) withRTF:
[NSData dataWithBytes: [rtfText UTF8String] length: [rtfText
length]]];
The file I write is properly formatted RTF and opens in Text Edit as
desired. The Text View, however, is filled with gibberish (properly
formatted gibberish for the most part, but gibberish). Is this a
problem with text encoding? Should I be using something other than
UTF8String?
You should make the NSData of the RTF text using
RTFFromRange:documentAttributes: rather from the UTF8 string. The two
codings are completely different.
That said, why not just use use
replaceCharactersInRange:withAttributedString: on the NSTextStorage of
the view?
Nicko
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden