为什么AppDelegate继承自UIResponder?
我注意到,当在 Xcode 4.2 beta 4 中使用 iPhone Master-Detail 模板创建新项目时,它会:
// AppDelegate.h
@interface AppDelegate : UIResponder <UIApplicationDelegate>
Why does AppDelegate
继承自UIResponder
而不是NSObject ?
I noticed that when creating a new project with the iPhone Master-Detail template in Xcode 4.2 beta 4, it does:
// AppDelegate.h
@interface AppDelegate : UIResponder <UIApplicationDelegate>
Why does AppDelegate
inherit from UIResponder
instead of NSObject
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
来自转换为 Storyboard 发行说明:
From Converting to Storyboards Release Notes:
查看
UIResponder
的文档。由于AppDelegate可以响应触摸事件,因此它实现了UIResponder
接口。Check the documentation of
UIResponder
. Since AppDelegate can respond to touch events, it implements theUIResponder
interface.UIResponder
是基类对于 UIKit 框架。UIResponder
可以处理事件。您的
AppDelegate
类是 的委托类UIApplication
其中UIApplicationMain
创建。AppDelegate
符合UIApplicationDelegate< /code>
协议。
UIResponder
类具有获取将填充所有视图的应用程序焦点窗口的方法,因此您应该有一个从UIResponder
继承的类,以便将窗口作为关键。UIResponder
is the base class for the UIKit framework.UIResponder
can deal with the events.Your
AppDelegate
class is the delegate class for theUIApplication
whichUIApplicationMain
creates.AppDelegate
conforms to theUIApplicationDelegate
protocol.The
UIResponder
class has the methods to get the window of the application focus on which all the views will be populated, so you should have a class that inherits fromUIResponder
in order to make the window as key.我猜是这样,所以它可以访问全局撤消管理器。
I would guess it is so it has access to the global undo manager.
AppDelegate继承自处理iOS事件的
UIResponder
。UIResponder
类为响应和处理事件的对象定义了一个接口。AppDelegate inherits from
UIResponder
that handles iOS events. TheUIResponder
class defines an interface for objects that respond to and handle events.更新:我下面的答案可能是错误的。我只是查看 iOS 文档中的图像。但是,它一定已经过时了。
除非 iOS 5 中有新内容且尚未记录,否则我认为这是 Xcode 4.2 beta 4 模板的拼写错误。在 iOS 应用程序中,应用程序委托应该子类化
NSObject
,而不是UIResponder
,例如:对于 iOS 应用程序,在 UIKit 中(对于 Cocoa Touch,例如 iPhone 和 iPad),
UIApplication
是响应者链中的最后一个响应者。对于 Mac OS X应用程序,在Application Kit(对于Cocoa,例如Mac)中,应用程序委托是响应者中的最后一个响应者链。
UPDATE: My answer below might be wrong. I was just going by the image in the iOS documentation. But, it must be outdated.
Unless there's something new in iOS 5 and not yet documented, then I think this is a typo with this Xcode 4.2 beta 4 template. In an iOS app, the app delegate should subclass
NSObject
, notUIResponder
, e.g.:For iOS apps, in UIKit (for Cocoa Touch, e.g., iPhone & iPad),
UIApplication
is the last responder in the responder chain.For Mac OS X apps, in the Application Kit (for Cocoa, e.g., Mac), the app delegate is the last responder in the responder chain.