Daniel Chen
Daniel Chen

Reputation: 2023

interact the navigation controller bar button with embed container view

enter image description here

I've created a UIViewController, and insert a container view in it, which embed a UITableViewController. As the image described above.

When user click the Table View Cell, I'd like to add a UIBarButton on the Navigation bar.

But, how can I manage this? I can rise the DatePicker when click on Table View Cell, but when I call self.presentingViewController in table view controller implementation file, it returns (null), same as when I call self.parentViewController

Upvotes: 3

Views: 5855

Answers (2)

Maverick1st
Maverick1st

Reputation: 3770

I'd suggest to implement the UITableViewController Delegates and Datasource Methods in the ViewController itself. That way you don't have to worry about accessing the ViewController containing the UITableView.

Upvotes: 0

rdelmar
rdelmar

Reputation: 104092

You're probably trying to access the parent controller too early. If you log self.parentViewController in viewDidLoad, it will return null, but it should return the correct controller from viewDidAppear, and certainly from the didSelectRowAtIndexPath method. Using parentViewController in this context is correct, not presentingViewController.

Upvotes: 6

Related Questions