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:
- the
nswindowcontrollermethodsetdocument:sets restoration class of document windows class of sharednsdocumentcontrollerobject.nswindowobject invalidates restorable state whenever state changes sendinginvalidaterestorablestateitself.- at next appropriate time, cocoa sends window an
encoderestorablestatewithcoder:message, , window encodes identification , status information passed-in encoder.when system restarts, cocoa relaunches app , sends
restorewindowwithidentifier:state:completionhandler:messagensappobject.apps can override method general work needed window restoration, such substituting new restoration class or loading separate bundle.
nsappdecodes restoration class window, sends therestorewindowwithidentifier:state:completionhandler:message restoration class object [in case, document controller's class —peter], , returnsyes.- the restoration class reopens document , locates window. invokes passed-in completion handler window parameter.
- cocoa sends the
restorestatewithcoder:message window, decodes restorable state passed-innscoderobject , 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: firstnsapplicationobject, eachnswindowobject,nswindowcontrollerobject,nsdocumentobject, , 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
Post a Comment