0

I have a container view embedded in a view controller. The container is used to display different view controllers. How can I change the title or add a button to the navigation bar in the parent?

Thanks!

1 Answers1

0

You can access the navigationItem that controls those attributes directly as so (assuming self = your childViewController:

[self.parentViewController.navigationItem setTitle:<Your Text>];
[self.parentViewController.navigationItem setLeftBarButtonItem:<Your Button>];
ebandersen
  • 2,362
  • 26
  • 25
  • You're calling 'self' from the childViewController, right? If so, NSLog(@"%@", self.parentViewController) and see what it's returning. I may not be understanding your viewController hierarchy correctly. – ebandersen Jun 25 '14 at 14:33
  • NSLog(@"%@", self.parentViewController) returns null – user3653821 Jun 25 '14 at 14:35
  • How are you adding these views to your parentViewController? If you do this programmatically like, [mainViewController addChildViewController:self.childViewController];, then self.childViewController.parentViewController will return mainViewController – ebandersen Jun 25 '14 at 14:38
  • [fromViewController willMoveToParentViewController:nil]; [self addChildViewController:toViewController]; [self transitionFromViewController:fromViewController toViewController:toViewController duration:0.45 options:UIViewAnimationOptionTransitionCrossDissolve animations:nil completion:^(BOOL finished) { [fromViewController removeFromParentViewController]; [toViewController didMoveToParentViewController:self]; self.transitionInProgress = NO; }]; – user3653821 Jun 25 '14 at 15:12
  • Haha, Yeah it is. Could you add those lines as an edit to your original post? – ebandersen Jun 25 '14 at 16:00