本文介绍了关闭模态视图时未调用ViewDidAppear的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我创建一个MainViewController.然后在MainViewController中,

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

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

当我关闭modalViewController时,在iPhone(iPhone 6+除外)上,将调用MainViewController的viewDidAppear.在iPad和iPhone 6+上,不会调用MainViewController的viewDidAppear.

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.

关闭modalViewController时,逻辑将调用一个函数.我怎么知道什么时候modalViewController被关闭.

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

推荐答案

关闭模态视图控制器时,可以使用委托在MainViewController中调用函数.例如:

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

MainViewController.h:

MainViewController.h:

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

@interface MainViewController : UIViewController <YourDelegate>

@end

MainViewController.m:

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:

ModalViewController.h:

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

ModalViewController.m

ModalViewController.m

// Wherever you dismiss..
[self dismissViewControllerAnimated:YES completion:^{
    [self.delegate someFunction];
}

这篇关于关闭模态视图时未调用ViewDidAppear的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 07:20