Is it proper to archive/unarchive NSWindowController?

☆樱花仙子☆ 提交于 2020-01-06 05:01:40

问题


I'm having a difficult time understanding what's going wrong. I have an NSWindowController with a NSWindow and a NSTextView. I want to archive that NSWindowController and NSWindow (along with all of its controls) to a file.

Then, I want to unarchive that same NSWindowController and the NSWindow and all views from the file. But Apple docs say:

Note: Although the NSWindow class inherits the NSCoding protocol from NSResponder, the class does not support coding. Legacy support for archivers exists but its use is deprecated and may not work. Any attempt to archive or unarchive an NSWindow object using a keyed coding object raises an NSInvalidArgumentException exception.

Importantly, if I encodeWithObject:windowController, this doesn't store the NSWindow. Therefore, when I do decodeWithObject for the windowController, the NSWindow isn't loaded.

How do I archive/unarchive the NSWindowController / NSWindow and all of its controls? What am I missing?


回答1:


Based on your answers, this is absolutely the wrong way to go about this. The only place an archived controller/view object graph makes sense is when it's archived as a nib/xib. A document contains data, not bits of the application's machinery.

If you're targeting anything below Lion, save your state somewhere in your document data when the document is saved and restore it when the document is loaded (see the various loading stages Document-Based Applications Overview for an understanding of where/when to do this).

If you're targeting Lion and above, the documentation isn't very detailed yet (and in some cases is completely nonexistent), but Lion supports EXACTLY this with very little effort on your part. See the WWDC 2011 videos, session 119 - Resume and Automatic Termination.



来源:https://stackoverflow.com/questions/6985334/is-it-proper-to-archive-unarchive-nswindowcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!