Delegates vs. events in Cocoa
- by aaronstacy
I'm writing my first iPhone app, and I've been exploring the design patterns in Cocoa and Objective-C. I come from a background of client-side web development, so I'm trying to wrap my head around delegates.
Specifically, I don't see why delegate objects are needed instead of event handlers. For instance, when the user presses a button, it is handled with an event (UITouchUpInside), but when the user finishes inputting to a text box and closes it with the 'Done' button, the action is handled by calling a method on the text box's delegate (textFieldShouldReturn).
Why use a delegate method instead of an event? I also notice this in the view controller with the viewDidLoad method. Why not just use events?