在我的基于NSPersistenDocument的项目中,我有一个这样的结构
myDocument (NSPersistentDocument) -> myDocument.xib (windows xib) | |-> view (the self.view) --> ... "other view" | |-> some NSArrayController | |-> myResourceViewController --> myResourceViewController.xib | |-> view (the self.view) | |-> myTreeController (a NSTreeController subclass)
基本上,myResourceViewController是一个viewController的一个实例,它管理resourceView并管理他们的数据.
在awakeFromNib方法myDocument我有以下代码
- (void)windowControllerDidLoadNib:(NSWindowController *)aController { ... [leftBar addSubview:resourceViewController.view]; //i add resourceViewController's view resourceViewController.view.frame = leftBar.bounds; ... }
在myResourceViewController awakeFromNib方法我有:
-(void)awakeFromNib; { NSLog(@"%@",[self description]); [removeButton bind:@"enabled" toObject:resourceTreeController withKeyPath:@"selection" options:[NSDictionary dictionaryWithObject:NSIsNotNilTransformerName forKey:NSValueTransformerNameBindingOption]]; NSArray *draggedTypes = [NSArray arrayWithObjects:ResourceURIPasteBoardType,nil]; [resourceOutlineView registerForDraggedTypes:draggedTypes]; }
NSLog表示,同一个myResourceViewController实例的awakeFromNib被称为4次,我不明白为什么.我唯一的ResourceViewController是在myDocument xib中创建的.我不使用NSNib加载方法到处.