访问容器视图控制器 [英] Access to container view controller

查看:139
本文介绍了访问容器视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有简单的ViewController有一个容器视图与TableViewController。
在ViewController我从外部API和该数据的一部分加载数据,我需要传递到容器中的TableViewController。

I have simple ViewController which have one container view with TableViewController. At ViewController I loading data from external API and one part of that data, I need to pass into TableViewController in container.

有任何方法如何做那?
谢谢!

Is there any way how to do that? Thank you!

推荐答案

容器视图中包含的控制器可以通过父控制器的self.childViewControllers 。如果你只有一个,那么它将在self.childViewControllers [0]。

The controllers contained in a container view can be accessed by self.childViewControllers from the parent controller. If you only have one, then it will be at self.childViewControllers[0].

注意: 在下面的注释中说明;这里是一个典型的例子,测试和工作:这只是在整个场景的VC。只需点击segue本身(即连接箭头中间的小符号)即可设置文本标识符。

Note: regarding RD's excellent technique explained in the comment below; here's a typical example, tested and working: this simply goes in the VC of the overall scene. Just click on the segue itself (ie, the small symbol in the middle of the connecting arrow) to set the text identifier.

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
    if ([segue.identifier isEqualToString:@"containerLogin"])
        self.vcLogin = (LoginVC *)segue.destinationViewController;

    if ([segue.identifier isEqualToString:@"containerStartNew"])
        self.vcStartNew = (StartNewVC *)segue.destinationViewController;

    }

这里只是如何在Swift中:注意解包器)

Here's just how to do it in Swift: (you have to be careful with the unwrappers)

override func prepareForSegue(segue:(UIStoryboardSegue!), sender:AnyObject!)
    {
    if (segue.identifier == "feedContainer")
        {
        feed = segue!.destinationViewController as! Feed
        feed.someFunction()
        }
    }

这篇关于访问容器视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆