I think I understand the logic behind a delegate. I got more the problem to use it. How many steps are involved? Do I have to use existing delegates? Or can I use my one ones?
In my example I got the AppDelegate that created many views (Objects / View Controllers) of the same type. Each view should somehow call a method on the AppDelegate to close itself. This would happen when a button within the view is touched. The method call would include the reference of the view (self).
So far I know from other languages responders, event listeners and so on. They are so simple to use.
Can anybody help me. I just found massive examples with a lot of code in the web. It can't be that hard to just call a parent in Objective C.
You can create your own:
In MyView1.h:
In MyView1.m:
In AppDelegate.h:
In AppDelegate.m:
An easy way to get what you want is to just start with one view. Then, have each other view be presented modally. When the button in the view is pressed do
[self dismissModalViewControllerAnimated:YES];
And here's something I made a while ago when I was starting iPhone development that might help you with delegates
I think you should use for this the
NSNotificationCenter
in you AppDelegate.m
this is the selector it will be called when the notification happens (we are still in the AppDelegate.m)
and in the ViewController.m when the button pushed (inside the method), you should post a notification like this: