1

I've got the following in my storyboard:

enter image description here

ViewA contains a Container and a UIView. The container has a Table View Controller embedded in it.

I want to action something in the Table which will affect the appearance of the UIView, so I need to call a method on ViewA from my Table View Controller.

I have followed this post - the 'Passing Data Back' section, which all makes sense. Passing Data between View Controllers The problem I have is the very last step where the controller is instantiated programatically.

The storyboard (or some ios framework component) is instantiating both Controllers for me.

So, my question is, how do I get a reference to the View instance that is automatically created for me from the other Controller.

From ViewA how to I get a reference to my TableViewController in order to set the delegate?

Community
  • 1
  • 1
user568280
  • 457
  • 2
  • 5
  • 9

2 Answers2

2

The two controllers have a child-parent relationship. From the table view controller, you can access A, with self.parentViewController. From A, you can access the table view controller with self.childViewControllers[0]. You can also implement prepareForSegue in A, and access the table view controller as the segue.destinationViewController; you should set A as the delegate there.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
0

At first you have to make storyboard identifier for your UITableViewController.

Than you can try this code...

ClassnameViewController *instance = (ClassnameViewController *) [self.storyboard instantiateViewControllerWithIdentifier:@"storyboardIdentifierSetByUser"];

instance.tableViewObject.delegate = self;

By using this you can access all the properties of ClassnameViewController.

Vijay Sanghavi
  • 340
  • 1
  • 5
  • 23