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

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

问题描述

iOS-Xcode中的文件所有者和第一响应者是什么?

What are File Owner and First Responder in iOS - Xcode?

推荐答案

文件所有者是实例化的 runtime 对象,该对象拥有笔尖的内容及其在加载笔尖时的出口/动作.它可以是您喜欢的任何类的实例-查看工具选项板的Identity选项卡.

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.

例如,考虑您有一个带有UILabel的IBOutlet的UIViewController子类.在界面生成器中,文件的所有者将设置为与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.

可通过以下方式加载碎块:

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.

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

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