0

I have a view controller B in a parent view controller A. Both views are showing the same time.

In view controller B, I'm trying to present a new view controller using the following method:

- (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:

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

But there is a difference between iOS 5.1 and iOS 6.

QN1: Upon dismissal, view controller A & B viewDidAppear are not invoked. Is it supposed to be triggered?

QN2: I can't get MyViewController to show up in iOS 5.1.1. unless I add view controller B as a child container to 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. viewDidAppear also gets called when using iOS6.

I'm not sure what is going on here.

Nora Olsen
  • 983
  • 2
  • 10
  • 22

1 Answers1

1

Answer 1 : viewDidAppear will not be called when you dismiss a modal view.

Answer 2 : if you are presenting "MyViewController" from "View-controller B" then View-controller B's view should be in view hierarchy.

From here you can get more information. How to Presenting View Controllers from Other View Controllers

Wolverine
  • 4,264
  • 1
  • 27
  • 49
  • For #2, I did a `po [[UIWindow keyWindow] recursiveDescription]` and the view hierarchy looks sane to me. UIWindow -> UIView (view controller A) -> UIView (View controller B) -> UIButton. I'm not sure where to look at? – Nora Olsen Jan 11 '13 at 12:34
  • I should also mention that this was without `[self addChildViewController:vcB];`, where self = view controller A. – Nora Olsen Jan 11 '13 at 12:41