我有一个nib文件,我在我的应用程序中的某个点加载.将NSWindow IBOutlet从我的AppDelegate链接到第二个nib文件的窗口是否合法?换句话说,我的IBOutlet没有连接到
Xcode默认创建的MainMenu xib文件.如果这是合法的,我可以访问NSWindow的框架和其他功能吗?
是的,你可以这样做.在你的第二个nib文件中,我将使用NSWindowController作为nib的文件所有者.然后在AppDelegate中,创建NSWindowController的一个实例,然后加载nib.从那里,您可以检查NSWindowController拥有的窗口的属性,或者使用窗口执行任何操作.
这是一个例子
@interface MyAppDelegate : NSObject { NSWindowController *myWindowController; } @end @implementation MyAppDelegate - (void)applicationWillFinishLaunching:(NSNotification *)aNotification { myWindowController = [[NSWindowController alloc] initWithWindowNibName:@"MySecondWindow"]; [[myWindowController window] center]; [[myWindowController window] makeKeyAndOrderFront:self]; } @end
精彩评论