什么是AppDelegate的,我怎么知道什么时候使用它? [英] What is the AppDelegate for and how do I know when to use it?

查看:147
本文介绍了什么是AppDelegate的,我怎么知道什么时候使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用iPhone应用程式。我如何知道我应该把东西在AppDelegate与一个自定义类?是否有一个规则或任何类型的另一种编程语言,如Python或PHP,使用AppDelegate像模式?

I'm just beginning to work on iPhone apps. How do I know when I should be putting stuff in AppDelegate versus a custom class? Is there a rule or any type of analogy with another programming language like Python or PHP that uses an AppDelegate like pattern?

推荐答案

通常避免安德鲁使用应用程序的核心一词暗示的设计方法。我的意思是,我认为你应该避免在一个中心位置过多的东西 - 良好的程序设计通常涉及分离功能的关注领域。

I normally avoid the design approach implied by Andrew's use of the term "heart of your application". What I mean by this is that I think you should avoid lumping too many things in a central location -- good program design normally involves separating functionality by "area of concern".

委托对象是当它所连接的对象达到某些事件或状态时被通知的对象。在这种情况下,应用程序委托是在UIApplication对象达到某些状态时接收通知的对象。在许多方面,它是一个专门的一对一观察者模式。

A delegate object is an object that gets notified when the object to which it is connected reaches certain events or states. In this case, the Application Delegate is an object which receives notifications when the UIApplication object reaches certain states. In many respects, it is a specialized one-to-one Observer pattern.

这意味着AppDelegate的关注领域正在处理特殊的UIApplication状态。其中最重要的是:

This means that the "area of concern" for the AppDelegate is handling special UIApplication states. The most important of these are:


  • applicationDidFinishLaunching: - 适用于处理启动配置和构建

  • applicationWillTerminate:

您应该避免在AppDelegate中放置其他功能,属于那里。这种其他功能包括:

You should avoid putting other functionality in the AppDelegate since they don't really belong there. Such other functionality includes:


  • 文档数据 - 您应该有一个文档管理器单例(对于多个文档应用程序)或文档单例单文档应用程序)

  • 按钮/表/视图控制器,查看委托方法或其他视图处理(除了在applicationDidFinishLaunching中构建顶级视图) - 此工作应在

许多人将这些东西整合到他们的AppDelegate中,因为他们是懒惰的,或者他们认为AppDelegate控制整个程序。你应该避免集中在你的AppDelegate,因为它困扰了应用程序中关注的领域,并不扩展。

Many people lump these things into their AppDelegate because they are lazy or they think the AppDelegate controls the whole program. You should avoid centralizing in your AppDelegate since it muddies the areas of concern in the app and doesn't scale.

这篇关于什么是AppDelegate的,我怎么知道什么时候使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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