Delegate to Self Concept!

2019-08-10 21:14发布

问题:

Spare me if you find this too basic and generic. But i hope answering would benefit lot of noobs out there like me.

Why we set Delegate to self?

Thanks,
Taimur

回答1:

You call a pizza parlor (object) and order a large pepperoni pizza (message).

The pizza parlor want to know who to call back (delegate) to say the pizza is on the way.

You give them your own number (self).



回答2:

For example, a UITable has two delegates, UITableDelegate and UITableDataSource...

Let's say, you want to subclass a UITable and your newly created subclass should not only enhance the functionality of the UITable but also manage it's content. Since the contents are managed by the UITableDataSource-Delegate, your new UITable subclass would implement this protocol and you would set the delegate of the UITable to itself.

Hope, this helps!