tags:

views:

17

answers:

1

I have a controller class which spawns a window when a certain condition occurs. This window can be closed by the user, moved around or resized.

Ideally, when this condition occurs, I'd like the window to re-open in the same spot the user closed it last time.

Looking for an elegant way to do this. Pointers (or references) will be most welcome.

+1  A: 

Luckily, AppKit knows this is a common pattern and has provided -setFrameAutosaveName:, which does this automatically for you. (If you're using NSWindowController you'll want to call setShouldCascadeWindows:NO, which will override this.)

kperryua
I create and launch my window from my controller without a XIB file. How can I "check" if there's a saved value and "apply" it myself when I create the window?
Ron M.
You don't need to. `-setFrameAutosaveName:` does the checking and applying for you. Just call the method at some point after creating it.
kperryua