iosobjective-ccontainer-view

How to update cells in a Container View


I have my storyboard set up like this:

  1. A view defined as a custom class, let's call it V1ViewController
  2. This view has a view container
  3. The view container has a UITableViewController with a set of static cells
  4. The cells are of style "Left Detail"

I'm trying to access the text box in the Left Detail from the code in V1ViewController, but can't seem to figure out how to traverse that hierarchy. Any help would be appreciated.


Solution

  • This is the proper way to get a reference to your child view controller:

    - (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
       if ([segue.identifier isEqualToString: @"childViewControllerSegue"]) {
           ChildViewController *myChildViewController = (ChildViewController *) [segue destinationViewController];
           //With myChildViewController you can access your child view controller for example:
           [myChildViewController.myTableView reloadData];   
       }
    }
    

    Keep in mind that because this is a Container view this method will be called upon load of your ViewController. Therefore it would be a good idea to save myChildViewController as a property or an instance variable for later use.