问题描述
在我基于 NSPersistenDocument 的项目中,我有一个这样的结构
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)
基本上,myResourceViewController 是一个viewController 的实例,它管理resourceView 并管理它们的数据.
basically, myResourceViewController is an instance of a viewController who manage resourceView and manage their data.
在myDocument的awakeFromNib方法中,我有以下代码
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;
...
}
在 myResourceViewControllerawakeFromNib 方法中,我有:
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];
}
NSLog 说,myResourceViewController 的同一个实例的awakeFromNib 被调用了4 次,我不明白为什么.我唯一的 ResourceViewController 是在 myDocument xib 中创建的.我不会到处使用 NSNib 加载方法.
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.
推荐答案
我找到了解决方案.每次 NSOutlineView
创建 NSTableCellView
时都会调用 awakeFromNib
.
I found the solution. awakeFromNib
is called every time a NSTableCellView
is created by NSOutlineView
.
这篇关于多次调用awakeFromNib 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!