我在Snow Leopard上运行xcode 4.2。我试图在Mac应用程序中显示一个面板,它将显示在主窗口旁边。这是代码:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
_propertiesViewController = [[NSViewController alloc] initWithNibName:@"FFPropertiesViewController" bundle:nil];
_panelController = [[NSWindowController alloc] initWithWindowNibName:@"FFPropertiesPanel"];
[(NSPanel*)[_panelController window] setBecomesKeyOnlyIfNeeded:YES];
[[_panelController window] setContentView:[_propertiesViewController view]];
[_panelController showWindow:self];
}
面板看起来很好,其控件看起来很实用。但是后来,当我创建一个自定义对象并尝试将其分配给NSViewController的representObject属性时,不会进行赋值。执行以下行会将representObject的值保留为nil:
_propertiesViewController.representedObject = aFieldInfo;
我试过给ViewController一个属性来引用FieldInfo对象,并在我试图分配代表对象的同一个地方分配它。效果相同 - 在赋值后,fieldInfo属性的值仍为零。这让我觉得ViewController有问题。也许我从笔尖那里检错了?
由于