Reputation: 1555
I have subclassed an nsview and want to implement the resume feature. Before i quit the application the encode code runs:
-(void)encodeRestorableStateWithCoder:(NSCoder *)coder
{
[coder encodeObject:[NSValue valueWithRect:self.originalFrame] forKey:@"originalFrame"];
[super encodeRestorableStateWithCoder:coder];
}
When starting the application again , restoreStateWithCoder is never called ?
Upvotes: 3
Views: 957
Reputation: 156
I just had the same problem and found the solution in the NSUserInterfaceItemIdentification protocol reference:
Identifiers are used during window restoration operations to uniquely identify the windows of the application. You can set the value of this string programmatically or in Interface Builder. If you create an item in Interface Builder and do not set a value for this string, a unique value is created for the item when the nib file is loaded. For programmatically created views, you typically set this value after creating the item but before adding it to a window.
I did create my view programmatically, so there was no identifier set for it and the window restoration mechanism didn't call the view restoration methods.
Before adding your view to the window, you need to set an identifier like this:
_exampleView.identifier = @"ExampleIdentifier";
If your view then calls [self invalidateRestorableState]
, the system will call encodeRestorableStateWithCoder
at the appropriate time and everything works as expected.
Upvotes: 3