0
votes

I have a UITableViewController embedded in a Container View. The UITableViewController has a delegate method I would like to access in the main view controller.

I am able to assign the view in the container to a property in the main view - however I cannot access the viewcontroller that is embedded and set it's delegate.

How can i do this? I can post code if required... Not sure what i can post that is useful!!!

2

2 Answers

0
votes

You should create a property in the main container view and assign the UITableViewController to it when it's created. Once that is done, you can call the desired delegate method by simply accessing this property. For example:

@interface ContainerViewController : UIViewController

@property (weak) UITableViewController *tableViewController;

@end


@implementation ContainerViewController

- (void)createTableViewController {

  self.tableViewController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
}

- (void)callTableViewControllerDelegate {

   if(self.tableViewController)
     [self.tableViewController delegateMethod];  //etc
}

@end
0
votes

OK... My problem was that I was trying to access the TableViewController via the container view itself.

What I should have done - and am now doing is look for the embed segue between the container view and the UITableViewController. It is then possible to set the delegate methods etc. as required!