Re: Reloading a window from NIB
Re: Reloading a window from NIB
- Subject: Re: Reloading a window from NIB
- From: Matt Neuburg <email@hidden>
- Date: Sun, 11 Mar 2007 09:12:25 -0700
- Thread-topic: Reloading a window from NIB
On Fri, 2 Mar 2007 12:57:14 +0300, Sergey Shapovalov
<email@hidden> said:
>Hello Cocoa-dev!
>
>(I've already tried to send this message to the list yesterday, but
>it looks like it
>didn't appear in the digest. So this is attempt number 2...)
>
>I am new to the list, so sorry if my question has been already
>discussed. However,
>a brief search in the archive found nothing relevant for me.
>
>I am developing a one-window Cocoa application. This means that the
>user can close
>the main window, then open it again, but he/she can't open 2
>instances of the main
>window. The behavior of the "New" command is redefined to just reset
>the state of
>all controls in the main window to the original state.
>
>To implement this behavior of the "New" command, I'd like to be able
>to reload the
>window in its original state as it is stored in the NIB. My question
>is as simple as:
>how can I do it?
>
>Should I set the "Release when closed" flag for the window? But if I
>do so, how
>shall I create it again on "New" command? Now Cocoa creates it for me
>automatically
>when the application launches. Will I have to re-initialize window
>controller by
>calling initWithWindowNibName manually? And generally speaking, is
>this a
>good idea or just a way to nowhere?
>
>Another approach I can see is using NSDocumentController. I think it
>can help
>just because in document-based applications, every new document window
>instance appears clean just like it is stored in NIB. But
>NSDocumentController
>is designed for document-based applications, which is not my case of
>application
>with just one main window. Can I employ it for my needs though?
>
>And well, if there's more than one way to make it work, which is
>better and why?
>Any advice will be appreciated!
Two obvious ways:
(1) When the user says to restore the original state of the window, you just
restore it, in code. You presumably know what the original state is, and
you're not allowing the user to change the original state, so this should be
trivial. Just tell all the things in the window what their state should be.
Or....
(2) Use a secondary nib containing the window, and "release when closed".
Load the nib to obtain the window. When the window closes, the window is
released. Load the nib again to obtain a fresh copy of the window. You might
find communication between nibs easier if you use an NSWindowController for
this. In that case, implement singleton on the NSWindowController and
release it when the window closes. m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden