Delegate to Self Concept!

不羁岁月 提交于 2019-12-11 11:52:22

问题


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!



来源:https://stackoverflow.com/questions/3790262/delegate-to-self-concept

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!