This code is from Utility app, added by Apple when creating a project.
What’s the difference between this:
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller
{
[self dismissModalViewControllerAnimated:YES];
}
And this:
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller
{
[controller dismissModalViewControllerAnimated:YES];
}
They both work, but the first one is the main code from Utility app, added by Apple.
So is there any difference, and why does self works? self is MainViewController, not FlipsideViewController. I have no idea, does it has something to do with delegation?
Thank you.
It all depends on which object is executing
flipsideViewControllerDidFinish; if it is the same as thecontroller, then it is just the same.In practice, what happens is that sometimes the class that is delegating (in your case
FlipsideViewController), also implements the delegate protocol (ie., acts as a delegate). In such case,selfandcontrollerare the same. This would correspond to a delegate intialization (eg. in the init method) like:But you could have your delegate be a different class (eg., the application delegate, or whatever) and in this case they would be different. In this case you would say (eg in init):
In this case, you application delegate would receive the call to
FlipsideViewControllerand thecontrollerargument tells which object it refers to; in this case,self!=controller.Another case is when your delegate is acting as a delegate for more than one object; in this case, the
controllerargument tells which object is the delegating one.In practice, within the delegate method implementation you can safely use the
controllerargument without much thinking.