关于File's Owner, First Responder, Application Delegate的解释

http://stackoverflow.com/questions/2305183/the-concept-of-files-owner-first-responder-and-application-delegate-in-iphone

  • File's Owner: This is the object that loads the xib file. In a completely generic sense, this is the object passed as the owner parameter to -[NSBundle loadNibNamed:owner:]. When working with a nib for a UIViewController subclass, this is usually the UIViewController subclass itself. Further reading: Resource Programming Guide: Nib Files

    One of the most important objects in a nib file is the File’s Owner object. Unlike interface objects, the File’s
    Owner object is a proxy object that is not created when the nib file is loaded. Instead, you create this object
    in your code and pass it to the nib-loading code. The reason this object is so important is that it is the main
    link between your application code and the contents of the nib file. More specifically, it is the controller
    object that is responsible for the contents of the nib file.
    In Interface Builder, you can create connections between the File’s Owner and the other interface objects in
    your nib file. When you load the nib file, the nib-loading code recreates these connections using the
    replacement object you specify. This allows your object to reference objects in the nib file and receive
    messages from the interface objects automatically.

 

  • First Responder: This is the view that receives untargeted events (i.e. those sent with a target of nil) first. The useful part of this is that it's connected to the idea of the responder chain, which is a mechanism by which things higher up in the view hierarchy can capture unhandled and deal with them. This concept originated on the Mac, and is particularly useful for implementing something like the "Copy" menu item. The first responder is the target of the "Copy" menu item, meaning that the selected text field gets a chance to handle the copy event first, then its superview, and so on. Further reading: iPhone Application Programming Guide: Event Handling
  • Application Delegate: This is simply the delegate of the application's UIApplication object. It typically receives general status messages about the application, such as when it starts, ends and what not. It's a good spot to kick off things that need to happen when your app starts or shuts down. Further reading: Cocoa Fundamentals Guide: Delegates and Data Sources
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值