问题描述
这很难用词,但我有一个包含容器视图的视图控制器 (vc1)(我正在使用情节提要).在该容器视图中是一个导航控制器和一个根视图控制器 (vc2).
This is tricky to word but I have a view controller (vc1) that contains a container view (I'm using storyboards). Within that container view is a navigation controller and a root view controller (vc2).
如何从 vc2 中访问 vc1?
From within the vc2 how can I get access to vc1?
或者,我如何将 vc1 传递给 vc2?(请记住,我正在使用情节提要).
Or, how do I pass vc1 to vc2? (baring in mind that I'm using storyboards).
推荐答案
您可以使用 Vc1 中的 prepareForSegue
方法,因为将 ContainerViewController 设为子级时会发生嵌入 segue.您可以将 self 作为 obj 传递或存储对孩子的引用以供以后使用.
You can use the prepareForSegue
method in Vc1 as an embed segue occurs when the ContainerViewController is made a child. you can pass self as an obj or store a reference to the child for later use.
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSString * segueName = segue.identifier;
if ([segueName isEqualToString: @"embedseg"]) {
UINavigationController * navViewController = (UINavigationController *) [segue destinationViewController];
Vc2 *detail=[navViewController viewControllers][0];
Vc2.parentController=self;
}
}
次要代码修复
这篇关于从容器视图的视图控制器中,如何访问包含容器的视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!