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:
Then in the SecondViewController class set up the ObjectImGoingToSendAMessageTo ivar and then just have a method like this:
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?
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];
Then in the SecondViewController class set up the ObjectImGoingToSendAMessageTo ivar and then just have a method like this:
Code:
- (void)somethingHappened {
[ObjectImGoingToSendAMessageTo doSomethingCool];
}
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?