应用程序委托在 xcode 项目中做什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4122185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 19:54:23  来源:igfitidea点击:

What does the app delegate do in a xcode project?

objective-cxcode

提问by TheAmateurProgrammer

Ok, so when I create a new cocoa project, there's always 2 files that's created for me. That's the .hand the .mNAMEAppDelegatefile. I've read a lot of books about cocoa and the documentary from apple that told me to create new files instead of using it. What's the point of those 2 files anyways? And is it safe to delete them?

好的,所以当我创建一个新的可可项目时,总会为我创建 2 个文件。这就是.h.mNAMEAppDelegate文件。我读过很多关于可可的书籍和苹果的纪录片,它告诉我要创建新文件而不是使用它。无论如何,这两个文件有什么意义?删除它们是否安全?

回答by jodm

Do not delete the App Delegate! This deals with the main "delegate" notifications for the application like:

不要删除应用程序委托!这处理应用程序的主要“委托”通知,例如:

  • When the application finished loading an is ready for you to add your first controller:

    -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;

  • When the application terminates:

    -(void)applicationWillTerminate:(UIApplication *)application;

  • 当应用程序完成加载后,您就可以添加第一个控制器了:

    -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;

  • 当应用程序终止时:

    -(void)applicationWillTerminate:(UIApplication *)application;

Check out this postfor more information on the app delegate.

查看此帖子以获取有关应用程序委托的更多信息。

The application delegate is one of the most important files in your project!

应用程序委托是项目中最重要的文件之一!

回答by Jayprakash Dubey

ProjectNameAppDelegate.hand ProjectNameAppDelegate.mfiles are created automatically during project creation. These are the first files to be executed. Consider them like a bootstrap for your application.

ProjectNameAppDelegate.hProjectNameAppDelegate.m文件在项目创建期间自动创建。这些是要执行的第一个文件。将它们视为应用程序的引导程序。