【发布时间】:2011-10-28 20:57:54
【问题描述】:
在我基于 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 是管理 resourceView 并管理其数据的 viewController 的一个实例。
在 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 说 myResourceViewController 的同一实例的 awakeFromNib 被调用了 4 次,我不明白为什么。我唯一的 ResourceViewController 是在 myDocument xib 中创建的。我不会到处使用 NSNib 加载方法。
【问题讨论】:
-
你确定是同一个对象吗?试试
NSLog(@"%p %@", self, [self description])。 -
是的,我用 NSLog(@"%@", [self description]);
-
myDocument.xib 是唯一的 nib 吗?
-
不,myResourceViewController 有一个名为 myResourceViewController.xib 的 xib。
标签: objective-c cocoa binding interface-builder xib