1

I have a UIViewController (StoreViewController), and in it's .xib is a UITableView to the left, and a standard UIView to the right. I have created a UITableViewController called StoreTableController and want to somehow make it the the controller of the table view within the StoreView.xib.

Unfortunately, I need to keep the File Owner of the nib file as StoreViewController. I have a delegate within the StoreTableController which has been set as the StoreViewController (this is for calling certain methods), and within the StoreViewController I have an instance of the StoreTableController.

So far I have tried keeping an outlet of the UITableView within StoreViewController and then doing this:

[self addChildViewController:self.tableController];

[self.tableController setTableView:self.table];

[self.table setDataSource:self.tableController];
[self.table setDelegate:self.tableController];

Where self.table is the outlet, and self.tableController is the instance of the StoreTableController.

However, I do not fully understand how to use UIViewController containment, so this is obviously incorrect.

I have tried variations of this as well, but really don't know what to do.

I have avoided using a UISplitViewController here because not only is the left view larger than the right, but also there are various things I plan to do which mean this must be done in a single .xib file if possible.

Any help is very much appreciated.

1
  • what exactly is your issue? are you not getting any delegate calls on StoreTableController for tableview? Commented Oct 29, 2012 at 9:45

1 Answer 1

2

First, put a regular UIView instead of a UIScrollView in your .xib. Connect it with an IBOutlet called "tableContentView".

Then, create a new instance of UITableViewController (or your custom class, derived from UITableViewController) in your code, and add its UIView to the tableContentView like so:

- (void)viewDidLoad
{
    [super viewDidLoad];

    //  Add tableView
    UITableViewController *someTableViewController = [[UITableViewController alloc] init];
    someTableViewController.view.frame = self.tableContentView.bounds;
    someTableViewController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    [self.tableContentView addSubview:someTableViewController.view];        
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.