In my iOS app, a user can select an image from a list, upon which they are presented with a modal that contains the image and options to delete the image. If the user chooses t
In my case I usually use block here.
For example you have ParentViewController.h
@interface ParentViewController : UIViewController
@end
Implementation ParentViewController.m
// INCLUDE HERE THE MODAL CONTROLLER TO HAVE ACCESS TO ITS PUBLIC PROPERTY
#import ModalViewController.h
@implementation ParentViewController
// implement your modal dismiss block here
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// DEFINE HERE THE CALLBACK FUNCTION
// 1. get the model view controller
ModalViewController *mvc = [segue destinationViewController];
// 2. Your code after the modal view dismisses
mvc.onDismiss = ^(UIViewController *sender, NSObject *objectFromModalViewController)
{
// Do your stuff after dismissing the modal view controller
.
.
.
}
}
@end
And, ModalViewController.h
@interface ModalViewController : UIViewController
// call back function, a block
@property (nonatomic, strong) void (^onDismiss)(UIViewController *sender, NSObject *objectYouWantToPassBackToParentController)
@end
ModalViewController.m
@implementation ModalViewController
.
.
.
// your dismiss function say
- (IBAction)dismissViewController:(id)sender
{
...
[self deleteImage];
[self dismissViewControllerAnimated:YES completion:^
{
// MAKE THIS CALL
self.onDismiss(self, theOjectYouWantToPassBackToParentVC);
}];
}
@end