Delegates vs. events in Cocoa
Posted
by
aaronstacy
on Stack Overflow
See other posts from Stack Overflow
or by aaronstacy
Published on 2011-11-24T22:19:10Z
Indexed on
2011/11/25
1:50 UTC
Read the original article
Hit count: 203
objective-c
|cocoa
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?
© Stack Overflow or respective owner