在我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