• 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: unexpected nil outlet
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: unexpected nil outlet


  • Subject: Re: unexpected nil outlet
  • From: Jonathan Hess <email@hidden>
  • Date: Tue, 17 Jun 2008 17:56:56 -0700

Hey William -

Assuming everything else is correct, it looks like your problem is that you're poking at 'window' too early. Your object receives the init message before IB has a chance to establish connections. If you think about it, IB has to create all of the objects before it can connect them. IB is still in the middle of the create objects phase of loading your NIB.

If you move your code to awakeFromNib you should see the results you expect.

So, remove the init method and replace it with:

- (void)awakeFromNib {
    [window setDelegate:self];
}

Jon Hess

On Jun 17, 2008, at 5:47 PM, William Squires wrote:

I'm trying to code a solution to the challenge "Make a Delegate" in chapter 6 of the new Hillegaas book. Here is my AppController.h

@interface AppController : NSObject
{
IBOutlet NSWindow *window;
}

@end

and my AppController.m

#import <Cocoa/Cocoa.h>
#import "AppController.h"

@implementation AppController

- (id) init
{
NSLog(@"init");
if ([super init])
 {
 // Register self as delegate
 NSLog(@"window = %@", window);
 [window setDelegate:self];
 }
return self;
}

- (NSSize) windowWillResize:(NSWindow *)sender toSize: (NSSize)frameSize
{
NSSize newSize;


NSLog(@"windowWillResize:toSize:");
newSize.height = frameSize.height;
newSize.width = frameSize.height * 2;
return newSize;
}

I then launched IB on MainMenu.xib, added an Object to MainMenu.xib window, changed its class to AppController, and connected its outlet to the window (right-click on object, then drag from the circle to the window.) I can confirm the connection is made in IB, but when I launch the app in Xcode (3.1), I get the message:

2008-16-07 19:40:44:335 WindowServer[2413:10b] window = (null)

from my NSLog() in the init() method! What (simple, stupid, dumbhead) thing have I missed?

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >unexpected nil outlet (From: William Squires <email@hidden>)

  • Prev by Date: Re: unexpected nil outlet
  • Next by Date: Re: Grand Central Details
  • Previous by thread: Re: unexpected nil outlet
  • Next by thread: Re: unexpected nil outlet
  • Index(es):
    • Date
    • Thread