views:

77

answers:

2

Hi Guys,

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

+6  A: 

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!

Phlibbo
You've interpreted the question as asking about `self.delegate = self`, whereas the poster might have meant `foo.delegate = self`.
tc.
+6  A: 

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).

hotpaw2
+1 for an awesome analogy. :)
zpasternack