• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Loading views from external nibs?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Loading views from external nibs?


  • Subject: Re: Loading views from external nibs?
  • From: Gonzalo Castro <email@hidden>
  • Date: Fri, 19 Jul 2002 13:16:39 -0400

On Friday, July 19, 2002, at 06:35 AM, cocoa-dev-
email@hidden wrote:

Date: Thu, 18 Jul 2002 20:56:52 -1000
Subject: Re: Loading views from external nibs?
Cc: email@hidden
To: Andrew Merenbach <email@hidden>
From: "Carlos A. Weber" <email@hidden>

On Thursday, Jul 18, 2002, at 18:16 Pacific/Honolulu, Andrew Merenbach wrote:

I have a program with lots of views (which are loaded into a main window), and each one has its own controller. I would like to save each view in its own nib file; I would like to load each one. I have a problem, though, and that is that I need to be able to access each view when I press certain buttons in the main window--and thus I need to connect them to the main controller. Unfortunately, connections in Interface Builder do not work over multiple files. Is there an easy way to do this, so that I don't spend so much time scrolling through views and controllers in Interface Builder?

I'll be surprised if the Apple-provided sample project located at /Developer/Examples/InterfaceBuilder/SimpleMultiWindow/ doesn't answer your question.


Yes, that's a good example if you want an entire window to come from a second nib file. However, if you want to add a view from a 2nd nib file to an existing window (which was the poster;s question) you have to take a few more steps. Here's how I've done it. [This is pseudo code. Add error checking.]

Step 1: In your 2nd nib file (MySecondNibFile.nib), create a window with one view inside it. This will be the view that will be added to your main window (which is defined in another nib). Add the UI you need to the view.

Step 2: Still in your 2nd nib file, create the actions and outlets in the File's Owner cube (dbl click it) which you'll need for connections to/from the view you created in the previous step. These connections to the File's Owner are merely stand-ins for the controller that will be instantiated at run time. Make your action and outlet connections to/from the view.

Step 3: Still in your 2nd nib file, create an NSWindowController subclass called View1Controller and connect the window you created in step 1 to it. Do not instantiate this controller here in the nib (it doesn't hurt but might confuse you later since it's not the one used at run time). Create the source files for the controller and add them to your project. Add the following function to View1Controller.m (you'll want to add all the action methods here too);
- (NSView *) myOnlyViewToBeUsedBySomeOtherWindow-Sniff- {
return [[[[self window] contentView] subviews]objectAtIndex:0];
}

Step 4: In your MainController.h add;
@class View1Controller;"

and inside the @interface block,
View1Controller * _view1Controller;
NSView * _view1;

Step 5: In your MainController.m add (to the part of your code when you want this view from the 2nd nib file to show up);
_view1Controller = [[View1Controller alloc] initWithWindowNibName:@"MySecondNibFile"];
_view1 = [_view1Controller myOnlyViewToBeUsedBySomeOtherWindow-Sniff-];
[[[self window] contentView] addSubview: _view1]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
  • Prev by Date: Crash problem in framework code
  • Next by Date: Re: Loading views from external nibs?
  • Previous by thread: Re: Loading views from external nibs?
  • Next by thread: Re: Loading views from external nibs?
  • Index(es):
    • Date
    • Thread