• 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
Why might my window be null after my nib is loaded?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Why might my window be null after my nib is loaded?


  • Subject: Why might my window be null after my nib is loaded?
  • From: Scott Ellsworth <email@hidden>
  • Date: Wed, 5 Apr 2006 16:01:16 -0700

Hi, all.

I am a bit mystified as to why [self window] is returning null after my nib is loaded, even though the window is visible.

(I have made a number of Cocoa apps previously, but they have all been document based. This app, like Memory Stick, say, shows data about a service in a window.)

I created an IWMainWindowController.m, an NSWindowController subclass, which contains only:

- (id)initWithAppDelegate:(IWAppDelegate *)delegate{
	NSLog(@"IWMainWindowController initWithAppDelegate");
    self = [super initWithWindowNibName:@"IWMainWindowController"];
    if (self) {
		[self setAppDelegate:delegate];
	}
	return self;
}

- (void)windowDidLoad{
NSLog(@"[IWMainWindowController windowDidLoad]");
NSWindow * window = [self window];
NSLog(@"window: %@",window);
NSView * contentView = [window contentView];
NSLog(@"view: %@",contentView);
float baseSize = 25.0;
[window setContentResizeIncrements:NSMakeSize(baseSize,baseSize)];
NSRect bounds = [contentView bounds];
NSLog(@"bounds: %@",NSStringFromRect(bounds));
int width = bounds.size.width/baseSize;
int height = bounds.size.height/baseSize;
NSLog(@"width,height: %d, %d",width,height);
for (int x=0; x<width; x++){
for (int y=0; y<height; y++){
NSView * subview = [[IWRectangularLEDView alloc] initWithFrame:NSMakeRect(x*baseSize,y*baseSize,baseSize,baseSize)];
[contentView addSubview:subview];
}
}
[contentView setNeedsDisplay:YES];
}


I created an IWMainWindowController.nib which has a window in it, and whose File's Owner is set to IWMainWindowController.

I created a subclass of NSObject called IWAppDelegate and instantiate it in the nib. It contains:

- (id)init{
NSLog(@"IWAppDelegate init");
self = [super init];
if (self) {
[self setMainWindowController:[[IWMainWindowController alloc] initWithAppDelegate:self]];
[[self mainWindowController] window];
}
return self;
}


When I run it, I see the log:

2006-04-05 15:53:26.261 NavComCocoa[2805] IWAppDelegate init
2006-04-05 15:53:26.263 NavComCocoa[2805] IWMainWindowController initWithAppDelegate
2006-04-05 15:53:26.325 NavComCocoa[2805] [IWMainWindowController windowDidLoad]
2006-04-05 15:53:26.325 NavComCocoa[2805] window: (null)
2006-04-05 15:53:26.325 NavComCocoa[2805] view: (null)
2006-04-05 15:53:26.326 NavComCocoa[2805] bounds: {{14.0358, -2}, {1.63035, 4.78681e-36}}
2006-04-05 15:53:26.326 NavComCocoa[2805] width,height: 0, 0


Now, I am confused. Why is my window null, given that the window actually did show up on the screen?

Scott


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Why might my window be null after my nib is loaded?
      • From: Ondra Cada <email@hidden>
  • Prev by Date: Re: UI Opinions, etc
  • Next by Date: Re: Why might my window be null after my nib is loaded?
  • Previous by thread: NSSaveOperationType in prepareSavePanel
  • Next by thread: Re: Why might my window be null after my nib is loaded?
  • Index(es):
    • Date
    • Thread