IBOutlet链接到嵌入式视图控制器 [英] IBOutlet link to embedded view controller

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

问题描述

我有一个复杂的iPad视图,我通过拥有多个视图控制器进行管理。我之前(在iOS6 / XCode 4.5之前)通过在代码中分配我的视图控制器来实现这一点,并通过链接到主视图将各种视图连接到它们。

I have a complex iPad view that I manage by having several view controllers. I previously (before iOS6/XCode 4.5) did this by allocating my view controllers in code, and hooked up the various views to them though links to the master view.

我想要做的是使用新的容器视图将视图控制器嵌入到storyboard文件中。我似乎无法将嵌入式视图控制器的IBOutlet链接发送到主控制器。

What I would like to do is use the new container views to embed the view controllers in the storyboard file. I don't seem to be able to make an IBOutlet link to the embedded view controller to the master controller.

是否可以这样做?或者通过标签或代码中的某些东西检索嵌入式控制器?

Is it possible to do this? Or to retrieve the embedded controller via a tag or something in the code?

这个问题特别关于使用容器视图

This question is SPECIFICALLY about using container views

推荐答案

我不确定你的意思是检索嵌入式控制器。如果要使用控制器,请使用UIStoryboard方法instantiateViewControllerWithIdentifier:,使用您在IB中为控制器提供的标识符。您还可以使用performSegueWithIdentifier:sender:方法(它还实例化视图控制器)。您应该查看Apple文档中的在应用程序中使用视图控制器部分。它还引用了子视图控制器与容器控制器同时实例化的事实。

I'm not sure what you mean by "retrieve the embedded controller". When you want to use a controller you use the UIStoryboard method instantiateViewControllerWithIdentifier:, using the identifier that you give to the controller in IB. You can also use the performSegueWithIdentifier:sender: method (which also instantiated the view controller). You should check out the "Using View Controllers in Your App" section in the Apple docs. It also makes reference to the fact that child view controllers are instantiated at the same time as the container controller.

编辑后:如果在另一个视图控制器中嵌入容器视图,嵌入式视图的控制器可以从包含控制器的self.childViewControllers引用(这将是一个数组,所以如果只有一个,你可以使用lastObject获取它。)

After edit: If you embed a container view in another view controller, that embedded view's controller can be referenced from the containing controller with self.childViewControllers (which will be an array, so if there is just one, you can get it with lastObject).

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

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