 |
 |
[NSTextView replaceCharactersInRange: withRTFD:] problem
|
 |
|
 |
|
Mac Elite
Join Date: Oct 1999
Location: San Jose, Ca
Status:
Offline
|
|
I am trying to put images into a NSTextView programaticly, and am running into a silent failure. I am using PublicBeta, so if this is fixed for this weekend's release, that would be nice to know too.
Here is a quick example of what is not working for me:
//imageWindow is pointer to a NSTextView defined using InterfaceBuilder
NSData *thisImage;
int dataLength;
thisImage = [NSData dataWithContentsOfFile:@"/Developer/Examples/Carbon/SimpleText/Sources/SimpleTextDoc.tiff"];
dataLength = [thisImage length];
//this works
[imageWindow setIntValue:dataLength];
[imageWindow replaceCharactersInRange: NSMakeRange(0, 0) withString: @"thisWorked"];
//this does not
[imageWindow replaceCharactersInRange: NSMakeRange(0, 0) withRTFD: thisImage];
Also, am I correct in noticing that you have to declare all of your temporary variables first thing in a method? Every time I try and mix them into code the compiler complains to me about it.
Karl Kuehn
larkost@softhome.net
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Sep 2000
Status:
Offline
|
|
thisImage = [NSData dataWithContentsOfFile:@"/Developer/Examples/Carbon/SimpleText/Sources/SimpleTextDoc.tiff"];
...
[imageWindow replaceCharactersInRange: NSMakeRange(0, 0) withRTFD: thisImage];
"RTFD" refers to the RTF format + graphics, which, in this context is represented as a serialized, flattened data stored in an NSData. So, an image is not an appropriate argument there.
The NSFileWrapper object represents an RTFD, or actually any file package, in memory. So, you can create an NSFileWrapper from your image, then flatten it, and pass it to the above method. Something like:
NSFileWrapper *wrapper = [[NSFileWrapper alloc] initFileWithContents:thisImage];
// (can also use initWithPath ath, and bypass the data)
NSData *serialized = [wrapper serializedData];
[imageWindow replaceCharactersInRange: NSMakeRange(0, 0) withRTFD: serialized];
[wrapper release];
There are several other ways to do this as well.
Also, am I correct in noticing that you have to declare all of your temporary variables first thing in a method? Every time I try and mix them into code the compiler complains to me about it.
Yes, Obj-C is compatible with C in this regard.
One more thing:
//this works
[imageWindow setIntValue:dataLength];
What was your intent with this? The setIntValue: is not needed. In fact, I didn't think NSText / NSTextView responded to this.
Ali
[This message has been edited by ali (edited 03-22-2001).]
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Oct 1999
Location: San Jose, Ca
Status:
Offline
|
|
Thanks, I was wondering how the NSTextView understood the difference between rich-text textual data, and images, but figured it just read the first part and stumbled over the data tags (hence only .tiff and one other art mentioned in the docs). I will use the new stuff tonight.... here's hoping.
The part with:
[imageWindow setIntValue:dataLength];
does work, but is totally undocumented. It is just like setStringValue and setFloatValue. They work without requiring a cast, I like them.. just hope they get documented so that they are suck in stone....
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|