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

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

  •  22-06-2023
  •  | 
  •  

Frage

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

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top