I happened across this recently, and I was wondering why this is designed as such.
If you have a UINavigationController
who has a child with a container view that has an embedded view controller in it, why does this child's self.navigationController
property not get set to something?
From the Apple Doc's on the subject:
The nearest ancestor in the view controller hierarchy that is a navigation controller. (read-only)
@property(nonatomic, readonly, retain) UINavigationController *navigationController Discussion If the receiver or one of its ancestors is a child of a navigation controller, this property contains the owning navigation controller. This property is nil if the view controller is not embedded inside a navigation controller.
To me, I would think because it's parent is embedded into the navigation controller, that it would pass it's reference down the chain to it's children. Am I missing something? Is there a good reason this is NOT the case?
Hi I had the same problem as you do. I fixed it by having this code to show the view 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 the AboutTheAppViewController (my controller that is going 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 it is helpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With