1
votes

When presenting a modal view controller how does one then interact with the parent view controller once the presented view controller is dismissed.

From what I understand viewWillAppear does not get called on the parent view controller when dismissing the modal view controller. How then does one update the UI based on the input taken in on the modal view controller?

Can the modal view controller call methods on it's parent view controller? i.e [self.parentViewController doWhatIWant];?

Or alternatively is there a method that gets called on the parent view controller when the modal view controller is dismissed?

1

1 Answers

3
votes

You can provide the modal controller with an instance of parent before displaying it modally, letting it call you back:

@class ParentViewController;

@interface ControllerToBeShownModally : UIViewController

@property (nonatomic, readwrite) ParentViewController* parentViewController;

// More items

@end

Displaying ControllerToBeShownModally:

ControllerToBeShownModally *ctrl = [[ControllerToBeShownModally alloc] init...];
ctrl.parentViewController = self; // Store the back reference here
[self presentModalViewController:ctrl animated:YES];

Calling back:

[self.parentViewController doWhatIWant];