0
votes

I am using a split view controller and wanting to add multiple table views to the master view controller.

So I can take advantage of prototype cells that (I believe) you can only get from UITableViewController I have put the UITableViewController into a second storyboard for the app. I am then substantiating it with:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"SecondStoryboard" bundle:nil];
MyTableViewController *myTableViewController = [storyboard instantiateInitialViewController];

I then add the view of this UITableViewController as a subview of my UIViewController.

[self.view addSubview:myTableViewController.view];

When I run this, I can select and highlight rows just fine. But didSelectRowAtIndexPath is not being called for some reason?

Thanks for any help, Richard

2
Did you set the delegate property of the UITableView? - mAu
I have checked in the storyboard and the delegate for the UITableView is setup correctly. Must be something in the way I have added the UITableViewController to the UIViewController that is blocking the call I guess. But is receiving touch events, as I said, because the rows are highlighting as expected when touched. - Richard
Where do you set the property? I once had the problem by setting the delegate to a table view in the init method. But you have to do it after the view has been loaded, so viewDidLoad would be the right place. Just to make sure this isn't the problem. - mAu

2 Answers

1
votes

Add this line

myTableViewController.view.delegate = myTableViewController;

or Make sure you have done the same in XIB(Interface Builder).

1
votes

Turns out that I needed to add the uitableviewcontroller as a child controller of the uiviewcontroller as well. Just adding the view alone was not enough.