有什么理由修改你的iOS应用程序中的main.m文件吗? [英] Is there any reason to modify the main.m file in your iOS applications?

查看:292
本文介绍了有什么理由修改你的iOS应用程序中的main.m文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更好地理解基本iOS应用程序中包含的每个文件的目的。

I'm trying to get a better understanding of the purpose of each file contained in a basic iOS application.

有没有理由修改main.m文件?我想知道这个文件是否需要被触摸。如果你修改它,为什么?

Is there any reason to modify the main.m file? I'm wondering if that file ever needs to be touched. If you do modify it, why?

推荐答案

在99.9%的情况下,没有必要触摸 main.m

In 99.9% of all cases, there is no need to touch main.m.

在其他0.1%中,您可能需要将调用的参数更改为 UIApplicationMain()函数。此函数的最后两个参数指定代表您的主应用程序(默认情况下为 UIApplication )和应用程序委托的类的名称。

In the other 0.1%, you might want to change the arguments of the call to the UIApplicationMain() function. The last two arguments of this function specify the names of the classes that represent your main application (UIApplication by default) and the application delegate.

如果你决定子类化 UIApplication ,你将把第三个参数设置为你的子类的名字。如果要拦截应用程序处理的某些事件(覆盖 sendEvent:),则子类化 UIApplication

Should you ever decide to subclass UIApplication, you would set the third argument to the name of your subclass. Subclassing UIApplication can be useful if you want to intercept certain events your app handles (override sendEvent:).

如果您只是决定重命名该类,则您的应用程序委托类的名称可能会更改。此外,如果 UIApplicationMain()的第四个参数是 nil (这是项目模板中的默认值,在iOS 5中的故事板),它表示您在应用程序的主要NIB文件中创建您的应用程序委托对象。如果你决定改变这个决定(例如,为一个现有项目修改Storyboarding),你必须改变第四个参数,以便告诉 UIApplicationMain()它应该实例化的类。

The name of your app delegate class might change if you simply decide to rename that class. Also, if the fourth argument to UIApplicationMain() is nil (which is the default in project templates that do not use Storyboarding in iOS 5), it signifies that you create your app delegate object in your app's main NIB file. Should you ever decide to change that decision (e.g., to adapt Storyboarding for an existing project), you would have to change the fourth argument in order to tell UIApplicationMain() the name of the class it should instantiate.

这篇关于有什么理由修改你的iOS应用程序中的main.m文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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