0

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

然后,我想取消归档相同的 NSWindowController 和 NSWindow 以及文件中的所有视图。但苹果文档说:

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.

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

如何归档/取消归档 NSWindowController / NSWindow 及其所有控件?我错过了什么?

4

1 回答 1

1

根据您的回答,这绝对错误的方法。存档的控制器/视图对象图唯一有意义的地方是当它被存档为 nib/xib 时。文档包含数据,而不是应用程序机器的一部分。

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

如果您的目标是 Lion 及以上,文档还不是很详细(在某些情况下完全不存在),但 Lion 完全支持这一点,您只需付出很少的努力。请参阅WWDC 2011 视频,第 119 节 - 恢复和自动终止。

于 2011-08-08T17:14:19.073 回答