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: The TVC on the right logs (null) for self.parentViewController.
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.
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 .
rdelmar provides the answer here: interact the navigation controller bar button with embed container view
can't access parent until viewWillAppear
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