objective c - NSDocument-based app window position

My Xcode NSDocument-based app contains a floating panel. On each launch of the app the default doc window and panel appear in their previous locations on the screen. However, if I save a document and quit the app then double click the saved file, the document window is positioned at the same origin as the panel.

Turning off cascading gets around the problem but of course I lose cascading.

A minimum Xcode example showing the issue can be downloaded here.

  1. Run the example project.
  2. Do a File/Save.
  3. Quit the app. << important
  4. Double click the saved file.

Any help appreciated.

2 Answers

  1. Laurent- Reply


    If you want to store the state of your window before the app terminates try this:

    - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
        // If you want to save your window position
        // you can use  [window saveFrameUsingName:@"someWindowName"];
        // then use [window setFrameAutosaveName:@"someWindowName"]; at the app launch.
        return NSTerminateNow;
  2. Lawrence- Reply


    I knew it had something to do with document windows cascading from the panel. Adding this to the panel controller seems to have fixed it

    - (void)windowDidLoad { [super windowDidLoad]; [self setShouldCascadeWindows:NO]; }

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>