Any idea what are the best practices for archiving an NSViewController
inside a window for resume (user interface preservation) purposes? I've tried archiving it in the window controller's encodeRestorableStateWithCoder:
methods only to find out that the view controller doesn't get unarchived when restoreStateWithCoder:
is called.
// NSWindowController subclass
-(void)encodeRestorableStateWithCoder:(NSCoder *)coder
{
[super encodeRestorableStateWithCoder:coder];
NSViewController* contentViewController = self.contentViewController;
if (contentViewController) {
[coder encodeObject:contentViewController forKey:BSContentViewControllerResumeKey];
}
}
-(void)restoreStateWithCoder:(NSCoder *)coder
{
[super restoreStateWithCoder:coder];
NSViewController* contentViewController = [coder decodeObjectForKey:BSContentViewControllerResumeKey];
if (contentViewController) {
// somehow this never get executed since contentViewController always comes out nil
self.contentViewController = contentViewController;
}
}
Note that this view controller contains other view controllers that manages their own subviews, and thus will need some scoping in the NSCoder
instance – simply passing the provided coder
object downwards will cause name clashes in the archive.
Thanks in advance!
-decodeObjectOfClass:forKey:
instead? – Symphony