UINavigationController and property of the navigation controller UIViewController

Recently, I came across this, and I was wondering why it was designed as such.

If you have a UINavigationController that has a child with a container view that has a built-in view controller, why does this child property of self.navigationController have no meaning?

From Apple Doc on the topic:

The closest ancestor in the hierarchy of the view manager, which is the navigation controller. (Only for reading)

@property (nonatomic, readonly, save) UINavigationController * navigationController discussion If the recipient or one of its ancestors is a child of the navigation controller, this property contains the navigation control controller. This property is zero if the view controller is not integrated into the navigation controller.

For me, I think, because he is the parent built into the navigation controller, that he will give him a chain link for him. Am I missing something? Is there a good reason this is not so?

+5
source share
1 answer

Hi, I had the same problem as you. I fixed this by pointing this code to the controller:

  UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]]; AboutTheAppViewController *loginVC = [storyboard instantiateViewControllerWithIdentifier:@"aboutMenuSegueID"]; [self addChildViewController:loginVC]; [loginVC didMoveToParentViewController:self]; [self.view addSubview:loginVC.view]; 

Then I add this to AboutTheAppViewController (my controller to be shown):

  -(void)willMoveToParentViewController:(UIViewController *)parent { NSLog(@"FirstViewController moving to or from parent view controller"); // self.view.backgroundColor=[UIColor blueColor]; } -(void)didMoveToParentViewController:(UIViewController *)parent { NSLog(@"FirstViewController did move to parent view controller"); // self.view.frame = CGRectMake(20, 20, 280, 528); } 

I hope this will be helpful.

+1
source

Source: https://habr.com/ru/post/1200944/


All Articles