简体   繁体   English

在iOS5.1 / 6中未调用presentViewController和viewDidAppear

[英]presentViewController and viewDidAppear not getting called in iOS5.1/6

I have a view controller B in a parent view controller A. Both views are showing the same time. 我在父视图控制器A中有一个视图控制器B。两个视图显示的时间相同。

In view controller B, I'm trying to present a new view controller using the following method: 在视图控制器B中,我正在尝试使用以下方法呈现一个新的视图控制器:

- (void) buttonClicked:(id)sender
{
    MyViewcontroller *vc = [[MyViewcontroller alloc] init];
    [self presentViewController:vc animated:YES completion:nil];
}

The view controller appears correctly in iOS6 and I dismiss MyViewController by using the following method: 视图控制器在iOS6中正确显示,并且我使用以下方法关闭了MyViewController

- (IBAction)backButtonPressed:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

But there is a difference between iOS 5.1 and iOS 6. 但是iOS 5.1和iOS 6之间有区别。

QN1: Upon dismissal, view controller A & B viewDidAppear are not invoked. QN1:解雇后,不会调用视图控制器A和B viewDidAppear Is it supposed to be triggered? 应该触发吗?

QN2: I can't get MyViewController to show up in iOS 5.1.1. QN2:我无法使MyViewController出现在iOS 5.1.1中。 unless I add view controller B as a child container to A: 除非我将视图控制器B作为子容器添加到A:

[self addChildViewController:vcB];
[self.view addSubview:vcB.view];

By adding the child controller, I can get MyViewController to show and view controller A&B viewDidAppear will be called when it gets dismissed. 通过添加子控制器,我可以让MyViewController显示并关闭视图控制器A&B viewDidAppear。 viewDidAppear also gets called when using iOS6. 使用iOS6时也会调用viewDidAppear

I'm not sure what is going on here. 我不确定这是怎么回事。

Answer 1 : viewDidAppear will not be called when you dismiss a modal view. 答案1:关闭模式视图时,不会调用viewDidAppear

Answer 2 : if you are presenting " MyViewController " from " View-controller B " then View-controller B's view should be in view hierarchy. 答案2:如果要从“ View-controller B ”中显示“ MyViewController ”,则视图控制器B的视图应位于视图层次结构中。

From here you can get more information. 从这里您可以获得更多信息。 How to Presenting View Controllers from Other View Controllers 如何从其他View Controller呈现View Controller

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM