Restoring saved fileWrapper items problem

  • MacOS 10.7.5 Lion Xcode 4.6.2

    My single window NSDocument app has 2 NSImages each in their own instances of my sub-classed NSImageView.
    It also has some colour wells and text labels. There are other objets I intend to add later.

    I override - (NSFileWrapper *)fileWrapperOfType:(NSString *)typeName error:(NSError *__autoreleasing *)outError
    and successfully save just the 2 images.

    Note: I am not saving anything else in the document. My thinking was why bother to duplicate what is already in the nib.

    To read the images back in again I have overridden  -(BOOL)readFromFileWrapper:(NSFileWrapper *)fileWrapper ofType:(NSString *)typeName error:(NSError *__autoreleasing *)outError

    Although I specifically set each NSImage it doesn't work because the problem seems to be that my 2 NSImageViews have not been instantiated. (Neither have the other objects for that matter.)

    Looking at the debugger frame list I see that makeDocumentWithContentsOfURL:ofType:error is called.
    I do actually get a new correctly titled window but it has the default images I would get if I had done New from the File menu.

    So it seems to me that I could  makeUntitledDocumentOfType:error the nib and then set the images. (then set the window title)

    But my thinking is probably wrong so please contribute to my education with your valuable suggestions.


  • You're prolly running afoul of the fact that the -read... call gets called before the NIB is loaded. In general, the recommendation is that you put your code to load the UI into a separate method, and keep the images in ivars. Then readXXX just sets the ivar, and the update UI method gets called in both windowControllerDidLoadNib and readXXX.

    Loading the images directly and then keeping them in the views violates Model-View-Controller.

    -- Uli Kusterer
    "The Witnesses of TeachText are everywhere..."
previous month may 2013 next month
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Go to today