Target-Action

The target-action design pattern offers a low-level way of responding to user interactions. You encounter this pattern almost exclusively with children of the UIControl class. With target-action, you tell the control to message a given object when a specific user event takes place. For example, you’d specify which object receives a selector when a user presses a button or adjusts a slider.

You supply an arbitrary selector. The selector is not checked at runtime, so use caution in preparing your code. The compiler will warn you if the selector specified is not declared, hopefully preventing a typo in the selector from going unnoticed and leading to a crash at runtime. The following snippet sets a target-action pair that calls the ...

Get The Core iOS Developer’s Cookbook, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.