When I change views from child to parent view, parents' viewWillAppear method not get called

StackOverflow https://stackoverflow.com/questions/22683071

  •  22-06-2023
  •  | 
  •  

Question

When I change views from child to parent view, parents' viewWillAppear method not get called

This is my code in Parent view.

PrivacyViewController *privacy = [[PrivacyViewController alloc]initWithNibName:@"privacyViewController" bundle:nil];
[self addChildViewController:privacy];
[self.view addSubview:privacy.view];
[privacy didMoveToParentViewController:self];

This is my code in Child view.

-(IBAction)backButton:(UIButton*)button
    [self willMoveToParentViewController:nil];
    [self.view removeFromSuperview];
    [self removeFromParentViewController];
}

Seems I do it right. 10x

Was it helpful?

Solution

The parent's viewWillAppear methods is not called when you modify its view. It is called only when it is showed, not when someone modify its view.

When you use the addChildViewController method, the viewWillAppear method is called on the child, not on the parent.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top