Currently, the default behavior of a Cocoa NSDocument based app is for it to open the last document that was opened automatically. How can I prevent this from happening so I can provide my own behavior?
Asked
Active
Viewed 114 times
1 Answers
0
I did this by adding this method to my NSDocument subclass:
- (void)addWindowController:(NSWindowController *)aController {
//
// Overwritten to reset all window restoration, we do our own.
//
NSWindow *window=[aController window];
if(
[window respondsToSelector:@selector(setRestorationClass:)]
&& [window respondsToSelector:@selector(setRestorable:)]
&& [window respondsToSelector:@selector(invalidateRestorableState)]
)
{
[window setRestorationClass:Nil];
[window setRestorable:NO];
[window invalidateRestorableState];
}
[super addWindowController:aController];
}
IIRC that was all.

Gerd K
- 2,933
- 1
- 20
- 23
-
This didn't work for me (and I have checked the code is getting called). – mz2 Jun 03 '17 at 11:36