【发布时间】:2012-06-30 21:22:00
【问题描述】:
我有一个消失的指针db;在创建NSDocument 期间正确设置了该值,但此刻我想打开一个子窗口,该值已更改为nil!我在NSDocument 子类中有以下内容:
@interface MW_Document : NSDocument
{
MW_WorkerWindowController *workerController;
__strong MW_db *db;
}
- (IBAction)showWorkerManagementPanel:(id)sender;
//- (IBAction)showSkillManagementPanel:(id)sender;
实现包含以下内容:
- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
[super windowControllerDidLoadNib:aController];
if (![self db]) {
db = [[MW_db alloc] init];
NSLog ( @"Debug - Init of db: [%ld]", db ); // never mind the casting problem
}
}
db 指向的不是 nil,而是一个真正的地址。
稍后,我想打开一个窗口并在同一个NSDocument子类的实现中拥有这个:
- (IBAction)showWorkerManagementWindow:(id)sender
{
if ( !workerController) {
workerController = [[MW_WorkerWindowController alloc] initWithDb:db];
}
[workerController showWindow:self];
}
我在第一行打了一个断点,看看db的值。它为零,但我不知道为什么。谁能给我解释一下?
【问题讨论】:
-
您是否尝试在
windowControllerDidLoadNib:中设置断点?更具体地说,您确定db = [[MW_db alloc] init];实际上被称为之前workerController = [[MW_WorkerWindowController alloc] initWithDb:db];?可能是workerController在调用-[showWindow:]之前不会加载其 NIB。
标签: macos cocoa nsdocument nswindowcontroller