Delegation
Table view data sources and delegates are examples of delegation, assigning responsibility for specific activities and information to a secondary object. Several UIKit classes use delegation to respond to user interactions and to provide content. For example, when you set a table’s delegate, you tell it to pass along any interaction messages and let that delegate take responsibility for them.
Table views provide a good example of delegation. When a user taps on a table row, the UITableView instance has no built-in way of responding to that tap. The class is general purpose, and it provides no native semantics for taps. Instead, it consults its delegate—usually a view controller class—and passes along the selection change. You add ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access