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

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

  •  22-06-2023
  •  | 
  •  

문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top