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: PGM <email@hidden>
- Date: Mon, 26 Nov 2007 21:24:50 +0100
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?
If the process is in this order you can actually base the
initialization on the data you receive, or actually even decide not to
do any initialization at all. You say it does make sense if you want
to do everything programmatically. The best way to implement something
automatically is to do it in the ame order as one would do it
programmatically. In that case it is much easier to choose which way
to use, or maybe use a combination of doing some things
programmatically and let the framework/IB deal with other parts.
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?
I would have retained the NSImage you got from the NSData as that more
closely represents your data model. Another way to do this would be to
use bindings to place the image in the imageView.
Cheers, Patrick
_______________________________________________
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