Re: Newbie question: NSDocument and standard file formats
Re: Newbie question: NSDocument and standard file formats
- Subject: Re: Newbie question: NSDocument and standard file formats
- From: Andrew Ebling <email@hidden>
- Date: Mon, 26 Nov 2007 13:45:35 +0000
Hi Jerry,
Thanks for your help - I've managed to figure this out as a result.
As you suggested, the code I posted was actually fine. The problem
was that the view had not been initialised by the time readFromData:
was being called, so I was successfully sending the message to a nil
object (the inner Java programmer in me finds this very weird!). The
initialisation order seems a bit weird to me - it would make sense if
you had to programmatically construct your view, but since it's all
handled for you, it seems strange that view initialisation isn't
handled first. Why is this?
So instead, I'm retaining the NSData object passed into readFromData:
and creating the NSImage object from it in awakeFromNib: and passing
that to the view for display. That works.
Is that the best way to do it, or can anyone think of a better solution?
Thanks again for taking the time to help me out.
best regards,
Andrew
On 26 Nov 2007, at 02:39, Jerry Krinock wrote:
On 2007 Nov, 25, at 7:25, Andrew Ebling wrote:
So my question is, without subclassing NSDocumentController (which
I understand you are not supposed to do), how do I tell
NSDocumentController to simply hand me back an instance of
NSImage? Or is it even already doing this for me and all I have to
do is get the class out of NSData? If so how?
Well, first of all, you can subclass NSDocumentController if you
have a need to.
Regarding the Cocoa Document Architecture (which as far as API is
concerned means NSDocument and NSDocumentController), it handles
things like open and save dialogs, associating them with windows,
splicing them into the responder chain, document change counts for
undo/redo, all the "generic" document stuff.
But the Cocoa Document Architecture does not do stuff with the data
in the file.
So, now that you understand that the problem is probably not with
your usage of the Cocoa Document Architecture, that brings us to
your code...
NSImage *img = [[NSImage alloc] initWithData:data];
[imageView setImage:img];
[img release];
I've never done that, but it looks like it should work. To
troubleshoot, start by doing an NSLog on 'data' to see if it is
what's in your file. Then NSLog the description of img, then
imageView, etc., etc.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden