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