没有MainMenu.xib的Cocoa应用程序 [英] Cocoa app without a MainMenu.xib

查看:310
本文介绍了没有MainMenu.xib的Cocoa应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于iOS(Cocoa Touch),可以转到main.m并替换 UIApplicationMain中的第四个参数(int argc,char * argv [],nil,nil)与您的应用程序的委托的类名,然后将根据需要构建视图。但是,Cocoa(Mac)项目在main.m中有以下内容:

  return NSApplicationMain(argc, argv); 

所以问题基本上是:如何将应用程序的委托传递给Cocoa应用程序而不使用MainMenu。 xib?

解决方案

您可以使用 setDelegate c> NSApplication 实例。下面是一个示例:

  AppDelegate * delegate = [[AppDelegate alloc] init]; 
[[NSApplication sharedApplication] setDelegate:delegate];
[NSApp run];对于返回值,您可以使用 EXIT_SUCCESS


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?

解决方案

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

这篇关于没有MainMenu.xib的Cocoa应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆