How can I add a table view controller to an existing storyboard view controller?

I'm creating a landscape iPad app for iOS 5.1 that should have two table views embedded into a view controller of my storyboard. What I would like to be able to do, is drag a table view controller onto the view controller in my storyboard. But of course, Xcode does not allow this. I can drag a table view and get its data hooked up and it works properly, but then I cannot push a new view controller to replace that table when a row is selected.

I cannot use the 'Editor > embed in > navigation controller' trick, because then the entire storyboard view controller (which contains my two table views) is embedded. That is not what I want.

There must be a way to do this programmatically, but I can't seem to get the right combo of voodoo and science to make it work.

I have tried to create a custom container view to hold my tableViewController, but the table isn't showing up.

Any thoughts?

- (void)viewDidLoad
{
    [super viewDidLoad];

    CGRect frame = CGRectMake(68, 187, 402, 474);
    _containerView = [[UIView alloc] initWithFrame:frame];
    _containerView.backgroundColor = [UIColor redColor];

    [self.view addSubview:_containerView];

    categoryController = [[UITableViewController alloc] init];
    categoryTable = [[UITableView alloc] init];
    categoryTable.delegate = self;
    categoryTable.dataSource = self;

    [categoryController.view addSubview:categoryTable];
    [_containerView addSubview:categoryController.view];
}

Answers


What you need is Container Views

Here are some tutorials that can help you:

http://www.cocoanetics.com/2012/04/containing-viewcontrollers/

http://weblog.invasivecode.com/post/12383262201/container-view-controllers-part-i-one-of-the

https://developer.apple.com/videos/wwdc/2011/?id=102


Need Your Help

Compiling java.exe on Windows using Visual Studio?

java windows jni

The C source for java.exe is included in the JDK. Has anyone ever managed to compile this code to an executable on Windows using Visual Studio?