View Full Version : delegates
Jun 20, 2008, 04:40 PM
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?
Jun 21, 2008, 04:13 AM
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.