0

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!!!

Jessica
  • 9,379
  • 14
  • 65
  • 136
HillInHarwich
  • 441
  • 6
  • 25

2 Answers2

0

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
Matt
  • 2,391
  • 2
  • 17
  • 18
  • Should this be in the uiviewcontroller that holds the container view, or a custom object for the container view? The container view is of UIView type... – HillInHarwich Apr 01 '13 at 13:24
  • Yes, this should be in the UIViewController that holds the container view. – Matt Apr 01 '13 at 15:39
  • I have declared a property for the uitableviewcontroller, i have implemented the delegate method, and I set up the uitableviewcontroller in the viewdidload function of the uiviewcontroller. I can't seem to connect the declared tableviewcontroller to the embedded object in the container view though... – HillInHarwich Apr 01 '13 at 16:01
  • The uitableviewcontroller i declare as a property is not null, and the delegate property I set is also not not null after i have finished initializing it. If i break though at the point where the delegate method should be called - the delegate of object is back to null... – HillInHarwich Apr 01 '13 at 16:09
  • I have checked in the navigation view controller and i cannot find where the view controller for the embedded view is at all... :-S completely confused – HillInHarwich Apr 01 '13 at 16:32
0

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!

HillInHarwich
  • 441
  • 6
  • 25