ios – 在解除模态视图时未调用ViewDidAppear

前端之家收集整理的这篇文章主要介绍了ios – 在解除模态视图时未调用ViewDidAppear前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
首先,我创建一个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];
}

猜你在找的iOS相关文章