您的位置:首页 > 其它

IT English Collection(18)of Target-Action

2013-10-11 20:52 316 查看

1 前言

    最近在忙着找工作,也没有继续写博客,不能不学习新知识啊,今天来补上一篇。有关Target-Action(目标-行动)模式的文章。

    转载请注明出处:http://blog.csdn.net/developer_zhang

2 详述

2.1 原文

    Target-action is a design pattern in which an object holds the information necessary to send a message to another object when an event occurs. The stored information consists of two items of data:
an action selector, which identifies the method to be invoked, and a target, which is the object to receive the message. The message sent when the event occurs is called an action message. Although the target can be any object, even a framework object, it
is typically a custom controller that handles the action message in an application-specific way.

    The event
triggering an action message can be anything, just as the object sending the message can be any object. For example, a gesture-recognizer object might send an action message to another object when it recognizes its gesture. However, the target-action
paradigm is most commonly found with controls such as buttons and sliders. When a user
manipulates a control object, it sends the message to the specified object. The control object is an instance of a subclass of UIControl (iOS) or NSControl (OS X). Both action selector and target object are properties of a
control object or, in the AppKit framework, properties of the control’s cell object.

An Action Method Must Have a Certain Form

    Action methods must have a conventional
signature. The UIKit framework permits some
variation of signature, but both
platforms accept action methods with a signature similar to the following:

- (IBAction)doSomething:(id)sender;

    The type qualifier IBAction, which is used in place of the void return type, flags the declared method as an action so that Interface Builder
is aware of it. For an action method to appear in Interface Builder, you first must declare it in a header file of the class whose instance is to receive the action message.

    The sender parameter is the control object sending the action message. When responding to an action message, you may query sender to get more information about the context of the event triggering the action message.

You Can Set Target and Action in Code or Using the Tools

    You can set the action and target of a control (or cell) object
programmatically or in Interface Builder. Setting these properties
effectively connects the control and its target via the action. If you connect a control and its target in Interface builder, the connection is archived in a nib file. When an application later loads the nib file, the connection is restored.

    You may set the target of an action message to nil. In this case, the application
determines the target at runtime; it sends an action message first to the first responder and from there it
goes up the responder chain until it is handled (if at all).

2.2 生词

Target
['tɑːgɪt] n. 目标;靶子
Action
['ækʃ(ə)n] n. 行动;活动;
trigger
['trɪgə]vt. 引发,引起;
paradigm
['pærədaɪm]n. 范例;词形变化表
manipulates
[mə'nɪpjʊleɪt]vt. 操纵;操作
conventional
[kən'venʃ(ə)n(ə)l]adj. 符合习俗的,传统的;
signature
['sɪgnətʃə]n. 署名;签名;
permit
[pə'mɪt]vi. 许可;允许
variation
[veərɪ'eɪʃ(ə)n]n. 变化;[生物]
变异
platforms
['plætfɔːms]n. 平台;
qualifier
['kwɒlɪfaɪə(r)]n. 限定词
be aware of
知道
programmatically
以编程方式
effectively
[ɪ'fektɪvlɪ]adv. 有效地,生效地
determine
[dɪ'tɜːmɪn]vt. 决定;判决;
go up增长;上升

3 结语

    以上是所有内容,希望对大家有所帮助。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: