Reputation: 2023
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
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
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