In Document-Based Apps, using XIB files, when a new window is created its behaviour is:
- Be positioned and sized based on the position of the last active window.
- If the last active window is still visible then the new window should be cascaded so it doesn't directly overlap.
However when using a storyboard this isn't done. See test project.
Cascaded Windows Problem
One of the problems is that storyboards unlike xibs can include the
NSWindowControllerand Interface Builder doesn't serialize it right.-initWithWindow:,-initWithWindowNibName:and friends setshouldCascadeWindowstoYES.When a
NSWindowControlleris loaded from a storyboard via-initWithCoder:,shouldCascadeWindowsisNO. (OS X 10.11)Based on my tests, this property needs to be set in the initializer. Setting it in
-[NSDocument addWindowController:]didn't work. (OS X 10.11)See rdar://47350352
Window Position Problem
Using
-[NSWindowController windowFrameAutosaveName]or-[NSWindow frameAutosaveName]seems only to work sometimes. Randomly it uses the initial window position.Window Size Problem
Even if the cascaded window position is set right, it never set the size to the one saved for the frame. I verified the saved frame with
defaults read window.autosavename.test1. Also before each test I rundefaults delete window.autosavename.test1for a clean state.Workaround
Use a xib containing a empty
NSWindowand add the view controllers from the storyboard in-[NSDocument windowControllerDidLoadNib:or-[NSDocument addWindowController:]to the window.