归档/取消归档NSWindowController是否合适? [英] Is it proper to archive/unarchive NSWindowController?

查看:95
本文介绍了归档/取消归档NSWindowController是否合适?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难理解出了什么问题。我有一个带有NSWindow和NSTextView的NSWindowController。我想将NSWindowController NSWindow(以及它的所有控件)存档到一个文件中。

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.

然后,我想要解压缩同样的NSWindowController和NSWindow以及文件中的所有视图。但Apple文档说:

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

注意:尽管NSWindow类继承了NSResponder的NSCoding协议,但该类不支持编码。存在对存档器的遗留支持,但其使用已被弃用,可能无效。任何使用键控编码对象归档或取消归档NSWindow对象的尝试都会引发NSInvalidArgumentException异常。

重要的是,如果我使用encodeWithObject:windowController,不存储NSWindow。因此,当我为windowController执行decodeWithObject时,不会加载NSWindow。

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

如何归档/取消归档NSWindowController / NSWindow及其所有控件?我缺少什么?

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

推荐答案

根据你的答案,这绝对 错误这样做的方法。归档控制器/视图对象图表唯一有意义的地方是将其归档为nib / xib。文档包含数据,而不是应用程序机器的位。

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.

如果您的目标是Lion以下的任何内容,请将您的状态保存在文档中的某个位置保存文档时的数据,并在加载文档时将其恢复(请参阅各种加载阶段基于文档的应用程序概述,以了解何时/何时执行此操作。)

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).

如果您是针对Lion及以上版本,文档还不是很详细(在某些情况下完全不存在),但是Lion只需要很少的努力即可完全支持。请参阅 WWDC 2011视频,会话119 - 恢复和自动终止。

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.

这篇关于归档/取消归档NSWindowController是否合适?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆