In iOS, using storyboard, how to setup a view controller inside a container view?(在 iOS 中,使用故事板,如何在容器视图中设置视图控制器?)
问题描述
我在我的主故事板中创建并绘制了一个名为 AutocompleteVC 的自定义 UIViewController.AutocompleteVC 将用于几个不同的地方/故事板和不同的维度.
I have created and drawn out a custom UIViewController called AutocompleteVC in my Main storyboard. AutocompleteVC will be used in several different places/storyboards and with different dimensions.
例如,在我的 Transit 故事板中,如下所示,有一个名为 TransitVC 的自定义 UIViewController,如左侧所示.在 TransitVC 中,我有一个带有名为 autocompleteContainerView 的 IBOutlet 的容器视图.autocompleteContainerView 对通用 UIViewController 有一个名为 autocompleteEmbedSegue 的 segue,如右侧红色所示.
For example, in my Transit storyboard, shown below,, there is a custom UIViewController called TransitVC, shown on the left. In TransitVC, I have a container view with an IBOutlet called autocompleteContainerView. autocompleteContainerView has a segue called autocompleteEmbedSegue to a generic UIViewController, shown on the right in red.
目标是让 TransitVC 在 autocompleteContainerView 中保存 AutocompleteVC.但我无法让这个工作.我想在容器视图中执行此操作的原因是我可以使用自动布局对其设置约束.否则,我知道如何纯粹在代码中做到这一点.
The goal is to have TransitVC hold AutocompleteVC inside autocompleteContainerView. But I'm having trouble getting this to work. The reason I want to do this inside a container view is so I can use autolayout to set constraints on it. Otherwise, I know how to do this purely in code.
我相信我的方法可能存在缺陷.如果我想最大限度地使用情节提要,正确的方法是什么.
I believe my approach might be flawed. What is the correct approach to do this if I want to maximize storyboard usage.
推荐答案
我不知道你在问什么.正如您所概述的那样,使用容器视图设置父/子关系非常容易.只需在父视图控制器中创建一个容器视图,创建子视图控制器场景,然后从容器视图中按住 control 拖动到子视图控制器,即可创建嵌入 segue.
I'm not sure what you are asking. Setting up a parent/child relationship with a container view is very easy, exactly as you have outlined. Just create a container view inside the parent view controller, create the child view controller scene, and then control-drag from the container view to the child view controller to create the embed segue.
这篇关于在 iOS 中,使用故事板,如何在容器视图中设置视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!