Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bkphat

macrumors newbie
Original poster
Jun 8, 2008
17
0
Hey,

I'm trying to understand what a delegate really is and how it is used.

For example, it seems to me that you can use them in subviews to trigger actions in the superview. Is this true?

thanks

bk
 
I'm not the most authoritative on this subject, but here goes.

Delegates exist to give you some control over the functionality of a class without having to create a subclass.

The subclass way:
1. Create a new class declared as a subclass of something else.
2. Create a constructor.
3. Call super() in the constructor.
4. Implement the methods you wish to over-ride.

The delegate way:
1. Create your controller class (which you probably already have)
2. Implement the delegate methods that you need.
3. Profit. :)

With the delegate way you don't have any extra framework code to write. You can just get right to the meat of what you are trying to accomplish.

Here are more details.
http://www.cocoadev.com/index.pl?DelegateObject

-numero
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.