新建项目
1 打开Xcode,选择OSX-》Application.下一步,不勾选StoryBoard
2 选择MainMenu.xib,删除Window.
3 新建CoCoaClass,SubClass of选择NSWindowController,勾选Also create XIB for user interface. 命名为MainWindowController.
4 选中新创建的MainWindowController.xib,选择Window,再属性栏,选择show the Attributes inspector,取消勾选Visible At Lanuch.
5 打开MainWindowController.m 重载windowNibName: 方法。
-(NSString *)windowNibName{
return @"MainWindowController";
}
6 打开AppDelegate.m,代码如下:
#import "AppDelegate.h"
#import "MainWindowController.h"
@interface AppDelegate ()
@property (strong)NSWindowController *mainWindowController;
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
MainWindowController *mainWC = [[MainWindowController alloc] init];
[mainWC showWindow:self];
self.mainWindowController = mainWC;
}
- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
}
@end