什么是iPhone SDK中的文件所有者和第一响应者 - xCode? [英] What are File Owner and First Responder in iPhone SDK - xCode?

查看:156
本文介绍了什么是iPhone SDK中的文件所有者和第一响应者 - xCode?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iPhone SDK中的文件所有者和第一响应者是什么?xCode?

What are File Owner and First Responder in iPhone SDK - xCode ?

推荐答案

文件所有者是实例化的,运行时对象,它在加载nib时拥有nib及其出口/操作的内容。它可以是您喜欢的任何类的实例 - 查看工具选项板的标识选项卡。

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.

文件所有者是应用程序代码与nib文件的内容。

File Owner is the main link between your application code and the contents of the nib file.

例如,假设你有一个UIViewController子类,其中包含一个UILabel的IBOutlet。在界面构建器中,File的所有者将被设置为与UIViewController相同的类。当您的笔尖在运行时加载时,笔尖中定义的出口和动作的绑定将绑定到视图控制器的实例,因为您的视图控制器是所有者。

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.

使用以下方式加载Nib:

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.

希望这很清楚。要在工作中看到这一点,请使用视图控制器创建一个全新的iPhone项目。打开Nib文件并查看标识选项卡。

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.

如果该文本字段具有焦点,则称其为链中的第一个响应者。因此,如果您向第一个响应者发送消息,它将首先发送到文本字段。如果文本字段无法处理该消息,则会将其发送到下一个响应者。接下来。接下来,直到你到达响应者链的末尾或某事消耗了事件(iirc)。

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).

响应者链值得一读 - 点击apple的文档了解更多信息。

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

这篇关于什么是iPhone SDK中的文件所有者和第一响应者 - xCode?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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