我正在尝试使用以下代码来工作。它第一次执行预期的操作并打开一个窗口并将其设置为前窗口,但是当它随后被调用时,orderFront:
由于 window 为 nil 而不起作用。为什么不设置从返回的对象initWithWindowNibName:
的窗口字段?NSWindowController
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