the typical behavior of the model view controller assumes that you are deflecting the modal view controller from the calling view controller, and not from yourself. not a hard rule, but good practice.
to accomplish this, create a protocol:
@protocol MyModalViewControllerDelegate - (void)modalViewControllerDidFinish; @end
and make both parentViewController and FirstModalViewController available for this protocol.
@interface FirstModalViewController <MyModalViewControllerDelegate>
then in FirstModalViewController.h and SecondModalViewController.h add:
@property id<MyModalViewControllerDelegate> modalViewControllerDelegate
in parentViewController and FirstModalViewController, just before calling presentModalViewController: ..., set the following:
modalViewControllerAboutToAppear.modalViewControllerDelegate = self; [self presentModalViewController:modalViewControllerAboutToAppear animated:YES];
next, in SecondModalViewController, in the code where you specify that the item should be fired, call
[self.modalViewControllerDelegate modalViewControllerDidFinish]
Now, in FirstModalViewController, do the following:
- (void)modalViewControllerDidFinish:(MyModalViewController*)controller { [self dismissModalViewControllerAnimated:YES] [self.modalViewControllerDelegate modalViewControllerDidFinish]; }
and finally, in the parent view controller, you can do:
- (void)modalViewControllerDidFinish:(MyModalViewController*)controller { [self dismissModalViewControllerAnimated:YES] }