Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ViewDidAppear not called when the modal view is dismissed

First, I create a MainViewController. Then in MainViewController, I do

[self presentViewController:modalViewController animated:YES completion:nil];
modalViewController.modalPresentationStyle = UIModalPresentationFormSheet;

When I dismiss the modalViewController, On iPhones(except iPhone 6+), viewDidAppear of MainViewController is called. On iPads and iPhone 6+, viewDidAppear of MainViewController is not called.

The logic is to called a function when the modalViewController is dismissed. How can I know when the modalViewController is dismissed.

like image 819
Gonghan Avatar asked Mar 26 '15 05:03

Gonghan


1 Answers

You can use a delegate to call your function in MainViewController when you dismiss the modal view controller. For example:

MainViewController.h:

@protocol YourDelegate <NSObject>
- (void)someFunction;
@end

@interface MainViewController : UIViewController <YourDelegate>

@end

MainViewController.m:

// Where you present the modal view
ModalViewController *view = [[ModalViewController alloc] init];
view.delegate = self;
[self presentViewController:view animated:YES completion:nil];

ModalViewController.h:

@interface ModalViewController : UIViewController
@property (nonatomic, weak) id<YourDelegate> delegate;
@end

ModalViewController.m

// Wherever you dismiss..
[self dismissViewControllerAnimated:YES completion:^{
    [self.delegate someFunction];
}
like image 180
DanielG Avatar answered Sep 28 '22 09:09

DanielG