1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

How to open a (previously closed) window?

Discussion in 'Mac Programming' started by jinksys, Jul 20, 2009.

  1. macrumors newbie


    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.
  2. macrumors 6502

    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
  3. macrumors newbie


    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!
  4. macrumors 6502

    good to hear! glad i could finally help someone! :)

Share This Page