Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Why use delegates?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="SoulRed12" data-source="post: 1052364" data-attributes="member: 146412"><p>I'll bet money that I'm missing something here, but I don't quite understand the point of jumping through hoops for delegates. I just learned how to use them, but what I don't understand is why.</p><p></p><p>Instead of doing all the set up work, why not just have a certain view controller assign itself as some sort of property (aside from the delegate property) and then just call a method from the view controller using the property? Like:</p><p></p><p>[code]//In the first view controller which is a subclass of UIViewController</p><p>//(Assume SecondViewController is another subclass of UIViewController)</p><p></p><p>SecondViewController *myViewController = [[UIViewController alloc] init];</p><p></p><p>myViewController.ObjectImGoingToSendAMessageTo = self;</p><p></p><p>[[self navigationController] pushViewController:myViewController animated:YES];</p><p>[myViewController release];[/code]</p><p></p><p>Then in the SecondViewController class set up the ObjectImGoingToSendAMessageTo ivar and then just have a method like this:</p><p></p><p>[code]- (void)somethingHappened {</p><p>[ObjectImGoingToSendAMessageTo doSomethingCool];</p><p>}[/code]</p><p></p><p>Wouldn't this accomplish the same thing (i.e. being able to send some message from the second view back to the first view)? Or is there something special about using protocols and delegates that I'm not understanding?</p></blockquote><p></p>
[QUOTE="SoulRed12, post: 1052364, member: 146412"] I'll bet money that I'm missing something here, but I don't quite understand the point of jumping through hoops for delegates. I just learned how to use them, but what I don't understand is why. Instead of doing all the set up work, why not just have a certain view controller assign itself as some sort of property (aside from the delegate property) and then just call a method from the view controller using the property? Like: [code]//In the first view controller which is a subclass of UIViewController //(Assume SecondViewController is another subclass of UIViewController) SecondViewController *myViewController = [[UIViewController alloc] init]; myViewController.ObjectImGoingToSendAMessageTo = self; [[self navigationController] pushViewController:myViewController animated:YES]; [myViewController release];[/code] Then in the SecondViewController class set up the ObjectImGoingToSendAMessageTo ivar and then just have a method like this: [code]- (void)somethingHappened { [ObjectImGoingToSendAMessageTo doSomethingCool]; }[/code] Wouldn't this accomplish the same thing (i.e. being able to send some message from the second view back to the first view)? Or is there something special about using protocols and delegates that I'm not understanding? [/QUOTE]
Verification
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Why use delegates?
Top