You use the delegate template for modal presentation to let you know who introduced it when it is finished.
MyModalViewController.h:
@protocol MyModalViewControllerDelegate; @interface MyModalViewController : UIViewController { id<MyModalViewControllerDelegate> delegate; } @property (nonatomic, assign) id<MyModalViewControllerDelegate> delegate; @end @protocol MyModalViewControllerDelegate - (void)myModalViewControllerFinished:(MyModalViewController*)myModalViewController; @end
MyModalViewController.m:
@synthesize delegate; // Call this method when the modal view is finished - (void)dismissSelf { [delegate myModalViewControllerFinished:self]; }
ParentViewController.h:
#import "MyModalViewController.h" @interface ParentViewController : UIViewController <MyModalViewControllerDelegate> { }
ParentViewController.m:
- (void)presentMyModalViewController { MyModalViewController* myModalViewController = [[MyModalViewController alloc] initWithNibName:@"MyModalView" bundle:nil]; myModalViewController.delegate = self; [self presentModalViewController:myModalViewController animated:YES]; [myModalViewController release]; } - (void)myModalViewControllerFinished:(MyModalViewController*)myModalViewController { [self dismissModalViewControllerAnimated:YES]; }
EDIT:
I have not used the UIImagePickerController
, but looking at the docs, it looks like you already have most of the code made for you, since there is an existing UIImagePickerControllerDelegate
that has three different โrejectsโ of delegate responses (although one of them is deprecated). Therefore, you must make your ParentViewController
class (whatever it is) implement the UIImagePickerControllerDelegate
template, and then implement these methods. Although each method will do something different (since you have to process it when the user really selects the image or cancels it), each of them will do the same at the end: call dismissModalViewControllerAnimated:
to reject the collector.
source share