Doesn't initialize initWithWindowNibName Window field
I am trying to use the following code. It does what is expected the first time and opens a window and makes it the front window, but when called subsequent it orderFront:
doesn't work because the window is zero. Why initWithWindowNibName:
doesn't it set the field of the object window NSWindowController
that is returned from initWithNibName:
?
//
// CustomerCard.m
// POSWonder
//
// Created by kaydell on 2/26/12.
// Copyright 2012 Kaydell Leavitt. All rights reserved.
//
#import "CustomerCard.h"
@implementation CustomerCard
// declare customerCard as a static variable
static CustomerCard* customerCard;
+(void) show {
// if the customer card isn't instantiated, then instantiate it
if (customerCard == nil) {
customerCard = [[CustomerCard alloc] initWithWindowNibName:@"CustomerCard"];
if (!customerCard.window) {
NSLog(@"Why is window nil here?"); // <<<<<<<<<<< This line gets called <<<<<
}
}
// show the customer card and make it the front window
[customerCard showWindow:self];
[customerCard.window orderFront:self]; // <<<<<<<< This line doesn't seem to do anything
}
-(void) dealloc {
customerCard = nil;
[super dealloc];
}
@end
source to share
I know this is an old question, but I wanted to answer my own question anyway.
-
I think using static variables and singleton maps for clients is not a good idea.
// declare the client card as a static variable
static client card * customerCard;
Now it seems to me that whenever you use static variables, you defeat the purpose of object oriented programming. Perhaps the user wants more than one customer card to view multiple customers in different windows.
- My idea of using a class method: "show", always showing the same customer card is not a good idea either. Now I think the user should have the freedom to choose New Customer Card from the File menu, or return to an existing customer card using the Window menu.
This is what I think now.
source to share