8

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.

Gonghan
  • 287
  • 2
  • 3
  • 10
  • Try using some other 'modalPresentationStyle'. Does it work then ? – itsji10dra Mar 26 '15 at 05:55
  • That is required by UX. I can't change it. – Gonghan Mar 26 '15 at 05:57
  • Are you calling : [super viewDidAppear:animated]; – itsji10dra Mar 26 '15 at 05:59
  • Yes, I called. I think the problem is that on iPhones, the modal view takes up the whole screen while on iPads, the modal view only is in the center. – Gonghan Mar 26 '15 at 06:03
  • I tried reproducing your scenario, here is [code](https://www.dropbox.com/sh/v1ggrwoq1hlgce3/AADB0vLx3jgrgThibS2zSmxGa?dl=0 "herequot;"). For me, its working on all device normally. Please, refer it. Hope it helps. – itsji10dra Mar 26 '15 at 06:13

2 Answers2

7

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];
}
DanielG
  • 2,237
  • 1
  • 19
  • 19
3

The way Apple supplied view controllers do this is to have a delegate on the presented view controller, that is called when that view controller requests to be closed. Then, the presenter would be responsible for dismissing the controller, and would thus also know when to do any associated clean up (both before and after the animation).

Dimitri Bouniol
  • 735
  • 11
  • 15