Skip navigation.
 
mlRe: Newbie question: NSDocument and standard file formats
FROM : PGM
DATE : Mon Nov 26 21:24:50 2007

> 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

Related mailsAuthorDate
mlNewbie question: NSDocument and standard file formats Andrew Ebling Nov 25, 16:25
mlRe: Newbie question: NSDocument and standard file formats Jerry Krinock Nov 26, 03:39
mlRe: Newbie question: NSDocument and standard file formats Heinrich Giesen Nov 26, 10:44
mlRe: Newbie question: NSDocument and standard file formats Andrew Ebling Nov 26, 14:45
mlRe: Newbie question: NSDocument and standard file formats Erik Buck Nov 26, 16:28
mlRe: Newbie question: NSDocument and standard file formats PGM Nov 26, 21:24