首先,我创建一个MainViewController.然后在MainViewController中,我做
[self presentViewController:modalViewController animated:YES completion:nil]; modalViewController.modalPresentationStyle = UIModalPresentationFormSheet;
当我解雇modalViewController时,
在iPhone(iPhone 6除外)上,调用MainViewController的viewDidAppear.
在iPad和iPhone 6上,未调用MainViewController的viewDidAppear.
逻辑是在解除modalViewController时调用一个函数.我如何知道modalViewController何时被解除.
解决方法
当您关闭模态视图控制器时,可以使用委托在MainViewController中调用您的函数.例如:
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]; }