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
nswindowcontroller
methodsetdocument:
sets restoration class of document windows class of sharednsdocumentcontroller
object.nswindow
object invalidates restorable state whenever state changes sendinginvalidaterestorablestate
itself.- 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:
messagensapp
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 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-innscoder
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: firstnsapplication
object, eachnswindow
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
Post a Comment