three windows two nibs

  • Hi All,

    [I am changing the subject title (MV and more than one C) since this
    post has drifted far from my original question. ]

    Basically, I am trying to understand how you load nibs and work with
    window controllers in non-doc apps. In my test application, two
    windows (windowA and windowB) are in the MainMenu.nib file, and a
    third window (windowC) is in a second nib file, WindowC.nib. The goal
    is to have all three windows be able to open each other when you
    press the right button. Thus, each window has a button that says
    "Open Window X" with X being the window in question.

    The way I set it up, it almost works....

    There is a main Controller for the MainMenu.nib and its two windows.
    These two windows (A and B) can open each other no problem.

    I also created a WindowCController class (subclassed from
    NSWindowController) to control the second nib file and its window
    (WindowC). windowControllerC is allocated and init'd when Controller
    loads. This enables me to access windowC from A and B.

    - (IBAction) openWindowC: (id) sender
    {
    [windowA close]; // I don't know which window is open so
    [windowB close]; // I closed both. Not elegant. How do you tell
    which is currently open?
    // Is windowController nil (just to make sure)?
    if (!windowCController) {
      NSLog(@"Creating windowCController from openWindowC.\n");
      windowCController = [[WindowCController alloc] init];
    }
    NSLog(@"Presumably about to show the window.");
    [windowCController showWindow: self];
    }

    This works (even though closing both windows A and B is not elegant.
    (How can you find out which window is open?)

    But I can't go the other way around and open windows A and B from
    Window C.

    I understand that to open a new nib you connect its window to a
    subclass of NSWindowController, and designate its File'sOwner to be
    the window controller.

    But once control is inside of the window controller, how can you get
    access backwards to variables inside of the Controller instantiated
    inside of MainMenu.nib (where you just came from). In other words,
    declaring windowControllerC as an instance variable of Controller
    gives you access to all the WindowC stuff, but how do you refer back
    to Controller and its instance variables windowA and windowB?

    I realize this must have a super simple answer, but I have hunted
    around and found nothing in the non-doc context. Thanks.
  • On Jan 18, 2008, at 3:03 PM, Daniel Child wrote:

    > Basically, I am trying to understand how you load nibs and work with
    > window controllers in non-doc apps
    >
    <http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/LoadingResources/
    CocoaNibs/chapter_3_section_1.html#//apple_ref/doc/uid/10000051i-CH4-SW8
    >

    mmalc
  • The article indicates that:

    "Upon the successful loading a nib file, its contents become ready
    for you to use immediately. If you configured outlets in your File’s
    Owner to point to the nib file objects, you can now use those
    outlets. If you did not configure your File’s Owner with any outlets,
    you need to retrieve the top-level objects for the nib file at load
    time. The top-level objects provide the entry points to the entire
    object graph contained inside the nib file."

    Here's the question. In the case of MainMenu.nib, the File's Owner is
    NSApplication by default. I thought of making my controller a
    subclass of NSApplication, but that might cause all kinds of
    unexpected problems. Besides, it's illogical, because the File's
    Owner needs to exist before the nib loads, and Controller is created
    when the nib loads, not before. Later in the article:

    The File’s Owner of the main nib file is always set to an instance of
    the NSApplication class. And although you might be able to
    instantiate a number of custom objects in your main nib file, doing
    so is hardly practical or necessary.

    There must be a way to access that instance of NSApplication. (It
    seems to be NSApp, a global variable created by +sharedApplication.)
    But that is still not access to Controller!!!???

    Sorry, I simply don't see the answer in that documentation. Maybe
    enough background allows you to see into the murky depths, but I
    don't have that kind of vision....

    On Jan 18, 2008, at 6:09 PM, mmalc crawford wrote:

    >
    > On Jan 18, 2008, at 3:03 PM, Daniel Child wrote:
    >
    >> Basically, I am trying to understand how you load nibs and work
    >> with window controllers in non-doc apps
    >>
    > <http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/
    > LoadingResources/CocoaNibs/chapter_3_section_1.html#//apple_ref/doc/
    > uid/10000051i-CH4-SW8>
    >
    > mmalc
    >
  • On Jan 18, 2008, at 5:35 PM, Daniel Child wrote:

    > Sorry, I simply don't see the answer in that documentation. Maybe
    > enough background allows you to see into the murky depths, but I
    > don't have that kind of vision....
    >
    You seem to be trying to do too much before you have a grasp of the
    fundamentals of Cocoa.
    I strongly suggest backing up and starting (perhaps again) with the
    basic tutorials.  All the questions you're asking are addressed in the
    documentation and in any of the introductory Cocoa books.

    mmalc
previous month january 2008 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today