Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add navigation item from view controller embedded in container view

Tags:

ios

I have a VC (the root VC of a navigation controller) with a container view. The container view embeds another VC. I believe this makes the latter a child VC of the former. I want to add a button to the navigation bar from the code for the child VC. I have tried using parentviewcontoller, but it doesn't work:

UIBarButtonItem *newConvoButton = [[UIBarButtonItem alloc] initWithTitle:@"New convo" style:UIBarButtonItemStyleBordered target:self action:@selector(newConvoInit:)];
self.parentViewController.navigationItem.rightBarButtonItem = newConvoButton;

And I know that code would work fine if it were in the parent VC and I removed the ".parentViewController".

So how can I add a navigation item from an embedded VC?

EDIT:

Here's a screenshot: 1 The TVC on the right logs (null) for self.parentViewController.

like image 481
mkc842 Avatar asked Jun 18 '13 18:06

mkc842


People also ask

How do I add a navigation bar to a table view controller?

Show activity on this post. From the outline view, make sure your Table View Controller is selected. Then go to the Editor menu, and click on the Embed In submenu, and choose Navigation Controller and voila. You have your navigation controller pointing to your tableview controller with a relationship built in.

How do I embed a view controller in navigation controller storyboard?

Step 1: Embed root view controller inside a navigation controller. In your storyboard, select the initial view controller in your hierarchy. With this view controller selected, choose the menu item Editor -> Embed In -> Navigation Controller .


1 Answers

rdelmar provides the answer here: interact the navigation controller bar button with embed container view

can't access parent until viewWillAppear

like image 69
mkc842 Avatar answered Sep 22 '22 22:09

mkc842