Cocoa app without a MainMenu.xib

2020-06-02 23:29发布

For iOS (Cocoa Touch), it's possible to go to your main.m and replace the fourth argument in UIApplicationMain(int argc, char *argv[], nil, nil) with the class name of your app's delegate, which would then construct the views as needed. However, Cocoa (Mac) projects have the following in main.m:

    return NSApplicationMain(argc, (const char **)argv);

So the question is basically: how do you hand over an app's delegate to Cocoa apps without a MainMenu.xib?

2条回答
We Are One
2楼-- · 2020-06-02 23:51

You can use setDelegate method of NSApplication instance. Here is a sample:

AppDelegate * delegate = [[AppDelegate alloc] init];
[[NSApplication sharedApplication] setDelegate:delegate];
[NSApp run];

As for return value you can use EXIT_SUCCESS

查看更多
疯言疯语
3楼-- · 2020-06-03 00:00

Subclass NSApplication, declare your subclass's name as the Application Class (or similar) property in Xcode. In your subclass you may override some function that gets called when the app is initialized, maybe -finishLaunching?

查看更多
登录 后发表回答