View Full Version : How to open a (previously closed) window?

Jul 20, 2009, 09:52 PM
This is what I have: Essentially the 'cocoa application' template with an AppController (NSObject) class added on. The AppController has been put in the main menu nib. The application loads a pdf into a pdfview (this part works), however I have a problem. I don't want the blank window to be shown at startup, and I also want to be able to recreate the window if another pdf is chosen after the window is closed. I have a (IBOutlet) NSWindow *window pointing to the window in the mainmenu.nib, and that connection is OK because I am able to zoom the window. I have a openPDFDialog method that is bound to the Open menuitem. In this method a NSopenpanel is used and pdfview is loaded with the pdfdocument. However, I can't get the window to show.

note: I am able to zoom the window if i let the window open at launch.

Jul 20, 2009, 11:58 PM
is the pdf window part of the same nib as the main application?
if it's in it's own nib then you can use the NSWindowController

otherwise you have to take that window in IB uncheck visible at launch in the inspector and also uncheck Release When Closed

then in your program hook up an IBAction method with this:

[myPDFWindow makeKeyAndOrderFront:self];
where myPDFWindow is the instance of the window in IB

it's probably a bad way of doing it but no one has said otherwise, it's probably best to use the NSWindowController and figure out how to link the nibs and xibs together some other way if they need to be

Jul 21, 2009, 12:18 AM
Thanks! I've got it working now. My program only has one window, which resides in the mainmenu.xib file. The program is only supposed to have one window open at a time so I figured using NSWindowControllers would have been overkill for this project. Your solution worked, thanks again!

Jul 21, 2009, 01:21 AM
good to hear! glad i could finally help someone! :)