Dispatching Events

Controls use target-action pairs to communicate changes triggered by events. When you build a new control, you must decide what kind of events your object will generate and add code to trigger those events.

Add dispatching to your custom control by calling sendActionsForControlEvents:. This method lets you send an event (for example, UIControlEventValueChanged) to your control’s targets. Controls transmit these updates by messaging the UIApplication singleton. As Apple notes, the application acts as the centralized dispatch point for all messages.

No matter how simple your class, make sure your control vocabulary is as complete as possible. You cannot anticipate exactly how the class will be used in the future. Overdesigning ...

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.