In my NSPersistenDocument based project i have a structure like this
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)
basically, myResourceViewController is an instance of a viewController who manage resourceView and manage their data.
in awakeFromNib method of myDocument i have the following code
- (void)windowControllerDidLoadNib:(NSWindowController *)aController { ... [leftBar addSubview:resourceViewController.view]; //i add resourceViewController's view resourceViewController.view.frame = leftBar.bounds; ... }
in myResourceViewController awakeFromNib methods i have:
-(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]; }
the NSLog say that awakeFromNib, of the same instance of myResourceViewController, is called 4 time, i don't understand why. My only ResourceViewController is created in myDocument xib. I don't use NSNib loading methods everywhere.
解决方案
I found the solution. awakeFromNib is called every time a NSTableCellView is created by NSOutlineView.
在我NSPersistenDocument基于项目我有一个这样的结构
myDocument中(NSPersistentDocument) - GT; myDocument.xib(窗口XIB) | | - >视图(self.view) - GT; ......另一种观点 | | - >一些NSArrayController的 | | - > myResourceViewController - > myResourceViewController.xib | | - >视图(self.view) | | - > myTreeController(一NSTreeController子类)
基本上,myResourceViewController是谁管理的ResourceView和管理他们的数据的viewController的一个实例。
在myDocument中的awakeFromNib方法,我有以下code
- (无效)windowControllerDidLoadNib:(NSWindowController *)aController { ... [leftBar addSubview:resourceViewController.view]; //我添加resourceViewController的看法 resourceViewController.view.frame = leftBar.bounds; ... }
在myResourceViewController awakeFromNib方法我有:
- (无效)awakeFromNib; { 的NSLog(@%@,[自我描述]); [removeButton绑定:@已启用toObject:resourceTreeController withKeyPath:@选择选项:[NSDictionary的dictionaryWithObject:NSIsNotNilTransformerName forKey:NSValueTransformerNameBindingOption]]; NSArray的* draggedTypes = [NSArray的arrayWithObjects:ResourceURIPasteBoardType,无] [resourceOutlineView registerForDraggedTypes:draggedTypes]; }
在的NSLog说awakeFromNib,myResourceViewController的同一个实例中,被称为4时,我不明白为什么。我唯一ResourceViewController在厦门国际银行myDocument中创建。我不使用NSNib加载方式随处可见。
解决方案
我找到了解决办法。 awakeFromNib 被称为每次 NSTableCellView 是 NSOutlineView 创建