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: Jim Correia <email@hidden>
- Date: Wed, 24 May 2006 18:45:15 -0400
On May 24, 2006, at 6: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);
First, a general comment about this code:
rtfdData is not initialized at declaration time. If the file exists,
you make the assignment. Otherwise, you use the variable anyway. This
needs to be fixed.
+[NSData dataWithContentsOfFile:] wants a file path, and you are
passing it the path to a directory (the .rtfd wrapper.)
AppKit provides methods to create an NSAttributedString from the
wrapper, which you can then use in the text view.
<http://developer.apple.com/documentation/Cocoa/Reference/
ApplicationKit/Classes/NSAttributedString_AppKitAdditions/
index.html#//apple_ref/doc/uid/TP40004007>
Jim
_______________________________________________
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