为什么不分类UIApplication?为什么要使用代理? [英] Why not subclass UIApplication? Why use a delegate?

查看:162
本文介绍了为什么不分类UIApplication?为什么要使用代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

而不是使用应用程序委托,以便 UIApplication singleton可以在预定义的时间调用委托方法,仅仅将子类化的优点和缺点是什么? > UIApplication ? (更新:为什么iOS架构使用应用程序代理,而不是让人们通过子类化 UIApplication 并覆盖其各种方法来编写应用程序?)

Instead of using an application delegate so that the UIApplication singleton can call the delegate methods at predefined time, what are the advantages and disadvantages of just subclassing UIApplication? (update: why does the iOS architecture use the application delegate instead of letting people write an application by subclassing UIApplication and overriding its various methods?)

这是因为当我们创建一个新的 UIView 控件时,我们子类 UIView 更新:或者我们子类 UIViewController )。那么为什么在应用的情况下,我们不会将 UIApplication 进行子类化,而是使用委托代替?

That's because when we create a new UIView control, we subclass UIView (update: or we subclass UIViewController too). So why for the case of application, we don't subclass UIApplication but use delegation instead?

推荐答案

再次,从文档中:


Subclassing Notes

Subclassing Notes

您可以决定将UIApplication子类覆盖sendEvent:或
sendAction:to:from:forEvent:实现自定义事件和动作
调度。但是,很少有必要扩展这个
类;应用程序委托(UIApplicationDelegate)在大多数情况下是足够的
。如果你做了子类UIApplication,那么确定你要用子类完成的

You might decide to subclass UIApplication to override sendEvent: or sendAction:to:from:forEvent: to implement custom event and action dispatching. However, there is rarely a valid need to extend this class; the application delegate (UIApplicationDelegate is sufficient for most occasions. If you do subclass UIApplication, be very sure of what you are trying to accomplish with the subclass.

这篇关于为什么不分类UIApplication?为什么要使用代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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