Re: How do I read RTFD files into a view?
Re: How do I read RTFD files into a view?
- Subject: Re: How do I read RTFD files into a view?
- From: Douglas Davidson <email@hidden>
- Date: Wed, 24 May 2006 15:44:02 -0700
On May 24, 2006, at 3:29 PM, Alan Smith wrote:
I can't get an NSView to replace its contents with the contents of a
RTFD file. I tracked the problem and it's that the NSData pointer
never loads the data.
NSData *rtfdData;
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
rtfdData = [NSData dataWithContentsOfFile:filePath];
NSLog(@"file does exist");
}
[helpViewer replaceCharactersInRange:NSMakeRange(0, [[helpViewer
string] length]) withRTFD:rtfdData];
NSLog(@"help file loaded: %@", filePath);
filePath is the path of the file I want it to load. :) helpViewer is a
NSTevtView. When I run this it does print out "file does exists but
can't load the data. What's up with that?
RTFD has two representations: an on-disk representation as a folder
hierarchy, and a serialized data representation used on the
pasteboard. You are looking at an on-disk RTFD folder and trying to
treat it as if it were a serialized pasteboard representation. Try
using -readRTFDFromFile: instead.
For more control you can work with the view's text storage using
AppKit NSAttributedString/NSMutableAttributedString methods such as
readFromURL:options:documentAttributes:error:. Remember that
NSTextStorage is a direct subclass of NSMutableAttributedString.
With NSAttributedString/NSMutableAttributedString methods of this
sort you don't need to know or care what type of file you are
reading--you can just let the text system take care of it for you;
although if you wish to require a particular type you may.
Douglas Davidson
_______________________________________________
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