我有打算在單擊按鈕時創建一個彈出窗口的應用程序。彈出窗口將從一個nib文件加載。所以,按鈕被點擊並且窗口愉快地彈出。但是,它的awakeFromNib方法被調用兩次。這是代碼;NSWindowController 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:]
。
誰能告訴我究竟做錯了什麼?
感謝
如果你有同樣的問題,但該地址是相同的??? – trumpetlicks 2017-06-23 19:38:51
然後,你應該打開一個新的問題與相關的細節。 – 2017-06-23 20:22:48