码迷,mamicode.com
首页 > 其他好文 > 详细

The File's Owner

时间:2015-03-06 23:39:33      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:

The File Owner is an instantiated, runtime object that owns the contents of your nib and its outlets/actions when the nib is loaded. It can be an instance of any class you like - take a look at the identity tab of the tool palette.

For example, consider you have a UIViewController subclass with an IBOutlet for a UILabel. In interface builder the File‘s owner will be set to the same class as your UIViewController. When your nib is loaded at runtime, the bindings of outlets and actions defined in your nib are bound to the instance of your view controller, as your view controller is the owner.

Nibs are loaded using:

[[NSBundle mainBundle] loadNibNamed:@"NibName" owner:nil options:nil];

The owner parameter is particularly important. That‘s the runtime instance of a class that owns the contents (outlets, actions and objects) of the nib being loaded.

Hopefully that‘s clear. To see this at work create a brand new iPhone project with a view controller. Open the Nib file and take a look at the identity tab.

First responder is simply the first object in the responder chain that can respond to events. The responder chain is a runtime collection (or more accurately a hierarchy) of objects that can respond to an event. For example, consider you have a window with a view and on that view is a text field.

If that text field has focus it‘s known as the first responder in the chain. So if you send a message to the first responder it‘ll be sent to the text field first. If the text field can‘t handle the message it‘ll be sent to the next responder. And the next. And the next, until you get to the end of the responder chain or something has consumed the event (iirc).

The responder chain is worth reading about - hit apple‘s documentation for more information.

The File's Owner

标签:

原文地址:http://www.cnblogs.com/welhzh/p/4319465.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!