setWindowFrameAutosaveName problems solved!
setWindowFrameAutosaveName problems solved!
- Subject: setWindowFrameAutosaveName problems solved!
- From: Darrin Cardani <email@hidden>
- Date: Tue, 16 Mar 2004 13:33:00 -0600
OK, I thought I'd share my pain and joy here so others might learn
from my mistakes. Last week I mentioned that I was having odd
problems with getting windows to automatically save their window
positions. The problem stemmed from the fact that each window has an
NSWindowController subclass associated with it, since these are
multiple windows that represent data in 1 document.
The first confusing part is that Interface Builder has a field for
the autosave name for each window you create. However, if you are
using a window controller, this information is overwritten when your
window controller's -initWithNibName: method is called.
So the next thing I did was attempt to call NSWindow's
-setFrameAutosaveName: within my document's
-windowControllerDidLoadNib: method. Apparently, calling the window's
method caused it to only happen for that specific window. That is, it
wouldn't be properly read in for other windows that used the same
window controller on subsequent runs. I didn't realize that there are
2 very similarly named methods:
-[NSWindowController setWindowFrameAutosaveName:]
and
-[NSWindow setFrameAutosaveName:]
So I was calling the NSWindow version when I should have been calling
the NSWindowController version.
But that wasn't the only problem. It turns out that if you set the
autosave name in Interface Builder, that causes -[NSWindowController
setWindowFrameAutosaveName:] not to work either, because the window
has the right autosave name initially. So when you attempt to set the
frame using the name by hand, it gets ignored because it sees that
there's already a window with that autosave name. This turned out to
be the crucial part that I had to figure out to solve the problem. I
had put the autosave names in the .nib file, so my calls to set it
were no longer working. I hadn't bothered to take them out when they
didn't work. But removing the autsave names from the .nib files and
making sure I was calling the NSWindowController method and not the
NSWindow method solved the problem and it now works.
Unfortunately, the docs don't make any of this clear to someone who's
never done this before. Looking through the archives of this list,
I'm guessing that others who ran into this problem had the same sorts
of problems I did. Hopefully this will help people overcome this
problem in the future!
Thanks,
Darrin
--
Darrin Cardani - email@hidden
President, Buena Software, Inc.
<
http://www.buena.com/>
Video, Image and Audio Processing Development
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.