在我NSPersistenDocument基于项目我有这样awakeFromNib方法调用多次
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和管理他们的数据。
在myDocument中的awakeFromNib方法我有下面的代码
- (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的说awakeFromNib,myResourceViewController的同一个实例中,被称为4次,我不明白为什么。我唯一的ResourceViewController是在myDocument xib中创建的。我不使用NSNib加载方法。
你确定它是同一个对象吗?试试`NSLog(@“%p%@”,self,[self description])``。 – hamstergene 2011-08-17 12:01:01
是的,我检查NSLog(@“%@”,[self description]); – 2011-08-17 12:03:44
myDocument.xib是否是唯一的笔尖? – paulmelnikow 2011-08-17 15:14:21