問題描述
NSWindow 的 IBOutlet 組件什麼時候初始化? (When IBOutlet components of NSWindow are initialized?)
I show modal subclassed window:
NSWindowController* controller = [[NSWindowController alloc] initWithWindowNibName: @"MyWindow"];
[NSApp runModalForWindow: [controller window]];
And I override initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag
in my window subclass to setup children views which are linked to nib file. But these children are not initialized at this moment (are nil).
Where to place my initialization code?
參考解法
方法 1:
The nib/xib loader creates the objects (with some of the constructrors from init
family) and setups their outlets in an undefined order. After they all exists and all the outlets are set up, then it sends awakeFromNib
to all objects from nib/xib files (which accept this message) so this is the right place where to perform most of the initialization.