获取容器VC而不是视图 [英] Get container VC instead of view

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

问题描述

我对容器的工作方式有些困惑。我有容器:

I'm a little confused how containers works. I have containers:

我尝试在我的 MainViewController 中进行管理。但是,当我将其拖放到.h文件中时,我会得到

And i try to manage this in my MainViewController. But when i control-drag it into my .h file i'm getting

@property (weak, nonatomic) IBOutlet UIView *liveContainer;

为什么这是UIView类?这意味着是self.view我的 BaseButtonContainerView 吗?但是我有 BaseButtonContainerViewController ,在调试中我看到 viewDidLoad 被调用了。我可以从 MainViewController 访问 BaseButtonContainerViewController 方法吗?

Why this is an UIView class? This mean that is self.view my BaseButtonContainerView? But I have BaseButtonContainerViewController, and in debug i see that viewDidLoad is called. Can i get access to BaseButtonContainerViewController methods from MainViewController?

推荐答案

故事板喜欢在 prepareForSegue 中进行所有操作,因此只需为您的segue分配一个标识符即可。在这种情况下,我们假设您在IB中将其设置为 baseButtonContainerSegue 。然后在 prepareForSegue 中使用:

Storyboards like to do everything in the prepareForSegue so just assign your segue an identifier. In this case we'll assume you set it to baseButtonContainerSegue in IB. Then in prepareForSegue use :

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

只需确保您拥有 UIViewController 属性 liveContainer ,(特别是在您的情况下,您需要一个 BaseButtonContainerViewController 属性)。我不确定为什么要用这种方式,但是我猜想它与内存管理有关。假设您离开该屏幕,并且容器已释放。然后,当您返回时,您可能会失去与它们的连接。这样,segues将再次被调用,您可以将其作为属性。同样,我不确定,所以如果有人这样做,请赐教!

Just make sure that you have a UIViewController property liveContainer, (specifically in your case you would want to have a BaseButtonContainerViewController property). I am not exactly sure why you have to do it this way but I am guessing it has something to do with memory management. Say you leave that screen and your containers are deallocated. Then when you go back you may lose your connection to them. This way the segues would be called again and you could grab them as properties. Again, I am not sure, so if someone else does please enlighten me!

这篇关于获取容器VC而不是视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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