• 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: LoadNib not working
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: LoadNib not working


  • Subject: Re: LoadNib not working
  • From: Stéphane Sudre <email@hidden>
  • Date: Tue, 5 Jun 2001 14:40:31 +0200

On mardi, juin 5, 2001, at 09:01 AM, Cyril Godefroy wrote:

Hi,

I have something rather strange happening: a nib which apparently loads but won't appear.
Here's the code:

- (void)showCountDown:(NSBundle*)bundle
{
if (![[bundle class] loadNibNamed:@"CountDown" owner:self]) {
NSLog(@"Failed to load CountDown.nib");
NSBeep();
return;
}
}

Why do you do a [[bundle class] loadNibNamed:...] and not a [NSBundle loadNibNamed:...] ?

I find this rather strange, and have very little code to compare with. First of all, this occurs in a dockling, so it might be a little specific. Also, I went around the tutorials and documentation and have not yet found a good explanation of nibs, how they load, what IBAction and IBOutlet are, and how multiple controllers talk to each other regarding their loading their nibs.

IBOutlet id is similar to id. It's just there to indicate that it's a widget.

In Interface Builder, when you create a Controller, which is often a subclass of NSObject, you can add Outlets and Actions to this Class.

These outlets are the IBOutlet in the resulting file as the IBAction are the actions of that class.

When you instantiate this class or make the File Owner to be of that class, you can create links between the Controller Instance and objects in the Interface. So that from the source code you can refer to the GUI objects using the IBOutlet name.

When it comes to controller talking. You need to have at least one main controller, which will load the other controller one way or the other.

The solution I'm currently using is the following one:

I have 1 main controller in the MainMenu.nib nib. This controller is created when the application is launched.

Within this controller, there are pointers to secondary controllers.

For each secondary controller, I have a .nib file, whose File owner is said to be an instance of the secondary controller class.

When the Main Controller is created, it allocates every second controller and then ask them to load their appropriate nib and indicate each secondary controller which its parent controller is. This allow every controller to know which its children and parent are.

Which gives use something like this in the mainController code:

- (id) init
{

[super init];
subController1 = [NeveruseNSSecondaryClassType1 alloc];
subController2 = [NeveruseNSSecondaryClassType2 alloc];

return self;
}

then:

- (void) awakeFromNib
{
[subController1 loadTabNib:self];
[subController2 loadTabNib:self];
}

In the NeveruseNSSecondaryClassType1 for instance:

- (void) loadTabNib:(id) sender
{
mainController_=sender;

if (!tabView_)
{
if (![NSBundle loadNibNamed:@"subcontrollerType1" owner:self])
{
NSLog(@"Failed to load subcontrollerType1.nib");
NSBeep();
return;
}
}
}

when the mainController wants to send a message to one of its childer, it uses the subController1 or subController2 "pointer".
When one secondary controller wants to send a message to its parent, it uses the mainController_ "pointer".


References: 
 >LoadNib not working (From: Cyril Godefroy <email@hidden>)

  • Prev by Date: Connecting actions to menu
  • Next by Date: Re: Newbie question regarding Learning Cocoa
  • Previous by thread: LoadNib not working
  • Next by thread: Re: LoadNib not working
  • Index(es):
    • Date
    • Thread