3

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

Daniel Chen
  • 1,933
  • 5
  • 24
  • 33

2 Answers2

6

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.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
0

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.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Maverick1st
  • 3,774
  • 2
  • 34
  • 50