Home

targetaction

Targetaction, often written as target-action or target-action pattern, is a user interface programming pattern in which a control or view (the sender) is configured with a target object and an action, typically a method or selector, to be invoked in response to a user event such as a click or tap. The pattern enables the control to delegate behavior to another object without embedding the logic inside the control itself.

In practice, the control stores a reference to the target and a representation of the action. When

Origins and platforms: The mechanism originated in NeXTSTEP and early Apple Cocoa frameworks; in Cocoa and

Variants and usage: A single action method can be shared by multiple controls; a single control can

Advantages and caveats: It promotes decoupling of UI from behavior and simplifies reuse, but it relies on

the
event
occurs,
the
control
sends
a
message
to
the
target,
invoking
the
action.
Depending
on
language,
the
action
may
receive
the
control
(the
sender)
as
a
parameter,
or
a
more
general
event
object;
many
frameworks
support
optional
sender
parameters.
Cocoa
Touch
it
is
implemented
via
selectors
and
runtime
messaging.
In
Interface
Builder,
developers
can
connect
controls
to
actions.
Some
other
platforms
implement
similar
concepts
under
different
names,
such
as
event
listeners
or
delegates.
be
bound
to
different
targets
programmatically.
The
pattern
supports
dynamic
binding
and
runtime
wiring,
enabling
changes
in
behavior
without
subclassing
the
control.
proper
lifecycle
management
to
avoid
sending
messages
to
deallocated
targets;
in
languages
with
weak
references,
ARC
semantics
help;
In
Swift,
actions
are
often
defined
with
@objc
and
#selector.