One window, multiple nibs?

  • Hey All

    I appreciate this question must come up all the time, but im
    struggling to find an answer to it (with an example of code too)

    I want to have a single window, but break parts out into separate nib
    files to keep things tidy. I presume that I just drop down a custom
    view in IB, then I need to link it up to the controller in which is
    calls the nib somehow?

    If someone could perhaps drop a small sample onto the list that would
    be awesome, or link to somewhere on the net where there is such a
    thing. People seem to talk about the powergurdian MDI example, but
    there site seems to no longer be there?

    Any help would be much appreciated

    Cheers

    Tim
  • Hi,
    maybe this bit of pseudo code helps.
    else.... look at the preferences controllr sample, maybe

    controller {

    init {
    loadNib(afile); //aWindow iboutlet
    loadNib(bfile); //bCustomView outlet
    loadNib(cfile); //cCustomView outlet
    }

    windowWillLoad {
    //set contentView
    window.contentView = bCustomView; // or cView
    }

    }

    Regards,
    Dominik

    Am Dec 3, 2007 um 1:05 PM schrieb Tim Perrett:

    > Hey All
    >
    > I appreciate this question must come up all the time, but im
    > struggling to find an answer to it (with an example of code too)
    >
    > I want to have a single window, but break parts out into separate
    > nib files to keep things tidy. I presume that I just drop down a
    > custom view in IB, then I need to link it up to the controller in
    > which is calls the nib somehow?
    >
    > If someone could perhaps drop a small sample onto the list that
    > would be awesome, or link to somewhere on the net where there is
    > such a thing. People seem to talk about the powergurdian MDI
    > example, but there site seems to no longer be there?
    >
    > Any help would be much appreciated
    >
    > Cheers
    >
    > Tim
  • It's fairly straightforward, assuming I'm remembering enough of the
    details after just getting up.

    First of all, set up a controller that has outlets for all of the nibs
    you want Let's call it "ViewController" Instantiate it somehow so it
    exists early on.

    Create each of your alternate view nibs (ViewA, ViewB, ViewC) and set
    the File's owner to ViewController. Create a new view in each nib and
    wire it up to the appropriate outlet (viewA, viewB, viewC, etc.). Note
    that you'll only wire up one of those views per nib file so your
    object's gonna have the indicator on it that connections are missing.
    This is okay.

    ViewController needs a method to switch views. Here's a stub method
    with other assumed stuff omitted.

    -(void) selectView:(id) aView {
      //if the view isn't loaded
      if (! [self isLoaded:aView]) {
        [NSBundle loadNibNamed:aView valueForKey:@"nib"] owner:self ];
        [self setLoaded:aView]; //note! this assumes that the nib loading
    always works
      }

      //note - this doesn't adjust the size of the window
      [[self window] setContentView:[self viewForName:aView]];
    }

    Fill in your own isLoaded, setLoaded, and viewForName methods.
    viewForName takes a name ("ViewA") and returns a view ([self viewA]).

    Don't forget to automatically select whichever one of those views
    should pop up at launch.

    -Jim....

    On 12/3/07, Tim Perrett <hello...> wrote:
    > Hey All
    >
    > I appreciate this question must come up all the time, but im
    > struggling to find an answer to it (with an example of code too)
    >
    > I want to have a single window, but break parts out into separate nib
    > files to keep things tidy. I presume that I just drop down a custom
    > view in IB, then I need to link it up to the controller in which is
    > calls the nib somehow?
    >
    > If someone could perhaps drop a small sample onto the list that would
    > be awesome, or link to somewhere on the net where there is such a
    > thing. People seem to talk about the powergurdian MDI example, but
    > there site seems to no longer be there?
    >
    > Any help would be much appreciated
    >
    > Cheers
    >
    > Tim
    >
  • http://www.cocoadev.com/index.pl?SharingNibsBetweenWindows

    The sample code about half way down the page should help you out.
    You link the controller to the view in the nib through the "File's
    Owner".

    Best,
    Cathy

    On Dec 3, 2007, at 1:05 PM, Tim Perrett wrote:

    > Hey All
    >
    > I appreciate this question must come up all the time, but im
    > struggling to find an answer to it (with an example of code too)
    >
    > I want to have a single window, but break parts out into separate
    > nib files to keep things tidy. I presume that I just drop down a
    > custom view in IB, then I need to link it up to the controller in
    > which is calls the nib somehow?
    >
    > If someone could perhaps drop a small sample onto the list that
    > would be awesome, or link to somewhere on the net where there is
    > such a thing. People seem to talk about the powergurdian MDI
    > example, but there site seems to no longer be there?
    >
    > Any help would be much appreciated
    >
    > Cheers
    >
    > Tim
  • Also note that in 10.5 I think the new class NSViewController is intended to
    help with this kind of thing.

    --
    Scott Ribe
    <scott_ribe...>
    http://www.killerbytes.com/
    (303) 722-0567 voice
previous month december 2007 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