我有一个应用程序打算在单击按钮时创建一个弹出窗口。弹出窗口将从 nib 文件加载。因此,单击按钮并愉快地弹出窗口。但是,它的 awakeFromNib 方法被调用了两次。这是代码;
申请代表:
...
-(IBAction)myButton:(id)sender{
printf("[settings]: button pressed\n");
Config_SelectorSetup *selectorSetup = [[Config_SelectorSetup alloc] initWithWindowNibName:@"Config_SelectorSetup"];
printf("about to load\n");
[[selectorSetup window] makeKeyAndOrderFront:sender];
}
Config_SelectorSetup.m
- (id) initWithWindowNibName:(NSString *)windowNibName{
printf("[initWithWindowNibName]\n");
if( self = [super initWithWindowNibName:windowNibName] ){
...
}
return self;
}
- (void)awakeFromNib{
printf("[awakeFromNib]\n");
[self startScreen];
}
这是输出:
[settings]: button pressed
[initWithWindowNibName]
about to load
[awakeFromNib]
[awakeFromNib]
分析调用堆栈,第一次被[NSObject performSelector:]
第二个调用[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:]
。
有人能告诉我我做错了什么吗?
谢谢