osx - Why aren't the init and windowControllerDidLoadNib: method called when a autosaved document is automatically open ? -


i have ns(persistent)document.

i run application via xcode, create new document (without data), , quit application. in case, can check init , windowcontrollerdidloadnib: called

if re-run application xcode, previous document automatically open. but, can check neither init nor windowcontrollerdidloadnib: called.

why ?

what you're seeing window restoration. document (part of document-based app programming guide) puts it:

the document architecture implements following steps in window restoration process; steps correlate numbers shown in figure 5-2:

  1. the nswindowcontroller method setdocument: sets restoration class of document windows class of shared nsdocumentcontroller object. nswindow object invalidates restorable state whenever state changes sending invalidaterestorablestate itself.
  2. at next appropriate time, cocoa sends window an encoderestorablestatewithcoder: message, , window encodes identification , status information passed-in encoder.
  3. when system restarts, cocoa relaunches app , sends restorewindowwithidentifier:state:completionhandler: message nsapp object.

    apps can override method general work needed window restoration, such substituting new restoration class or loading separate bundle.

    nsapp decodes restoration class window, sends the restorewindowwithidentifier:state:completionhandler: message restoration class object [in case, document controller's class —peter], , returns yes.

  4. the restoration class reopens document , locates window. invokes passed-in completion handler window parameter.
  5. cocoa sends the restorestatewithcoder: message window, decodes restorable state passed-in nscoder object , restores details of content.

[figure 5-2, , paragraph explaining views, other responders, , document saved , restored, too]

when app relaunched, cocoa sends restorestatewithcoder: message relevant objects in turn: first nsapplication object, each nswindow object, nswindowcontroller object, nsdocument object, , each view has saved state.

the window restoration protocol used non-document-related windows, too, document machinery handles of dirty work you. if need on either side (probably both sides) of window restoration, override encoderestorablestatewithcoder: , restorestatewithcoder: in document. former save transient information selections, , latter restore information in resurrected document , window(s).

the presence of coders implies document initialized using initwithcoder: rather init, though isn't documented fact (in context of window restoration) should rely upon.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -