Getting RTFD data into an NSData object.
Getting RTFD data into an NSData object.
- Subject: Getting RTFD data into an NSData object.
- From: Mark Stockwell <email@hidden>
- Date: Sun, 4 Jul 2004 18:21:29 -0500
I'm trying to implement a master-detail interface with the detail
coming from a big ol' NSTextView. I had it working with simple strings,
but I want it to work with embedded pictures, formatting and such like
that. So whenever I change items: I get an NSTextStorage object from
the NSTextView, grab an NSData object from the NSTextStorage object,
and I save that with my item for later like this:
NSTextStorage* textStorage=[detailTextView textStorage];
NSRange range = NSMakeRange(0, [textStorage length]);
NSData *data = [detailTextView RTFDFromRange:range];
if (data != nil) [[item properties] setObject: data forKey: @"detail"];
That part seems to work. What I can't figure out how to do, though, is
initialize my item the first time when I have no NSTextView to grab an
NSTextStorage item from. I've tried stuff like:
NSString *s = @"Detail";
NSData *data = [[NSData alloc] initWithBytes:[s cString] length:[s
length]];
NSArray *values = [NSArray arrayWithObjects: [NSNumber
numberWithInt:0],[NSDate date], data, @"item", nil];
but when I try to access that object with this code:
NSData* data = [[item properties] objectForKey: @"detail"];
NSTextStorage* textStorage=[detailTextView textStorage];
NSRange range = NSMakeRange(0, [textStorage length]);
[detailTextView replaceCharactersInRange:range withRTFD:data];
I get this error message:
Unable to read RTFD from
data:0x3ae7b0
I can't seem to find any way to put some RTFD data into an NSData
object without reading it in from a file. How do I do it?
Thanks,
Mark
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.