Parameters for a Container View

Asked

Viewed 180 times

1

The scenario is as follows:

I own a UIViewController and within this controller I own one UITableViewController added as a ContainerView.

How do I pass parameters between my UIViewController and my ContainerView?

For example, I want to get past mine UIViewController a list of items to be presented in my ContainerView (UITableViewController).

1 answer

2


Just you simply have a public method in your UITableViewController and execute it by UIViewController. Let’s assume that your UITableViewController has the following method in its header:

- (void)preencheTabela:(NSArray *)lista;

And the implementation:

- (void)preencheTabela:(NSArray *)lista {
    // TODO preencher sua lista atual com a recuperada
    [self.tableView reloadData];
}

And in his UIViewController, once you have the reference of the Controller with the table that was inserted in container, just run your method:

[self.referanciaTabela preencheTabela:listaEnviada];

Clarifying that it is not for the container that you will pass, and yes to the Controller that’s inside the container. It was clear?


Your reference, already with the container added from the storyboard, is more or less like this, in the viewDidLoad: for example:

self.referanciaTabela = [self.childViewControllers firstObject];
  • Yes, I understood, but my doubt is that she is already created via storyboard, so she is automatically already inside this container. So I don’t have my container controller instantiated in my Uiviewcontroller

  • Okay, no problem since you just get the reference on viewDidLoad: with the first element of childViewControllers. I added an edit to my reply.

  • Thanks, it worked out here, first time working with Container View I was a little bit scared

Browser other questions tagged

You are not signed in. Login or sign up in order to post.