在容器视图中的视图控制器中,如何访问包含容器的视图控制器? [英] From within a view controller in a container view, how do you access the view controller containing the container?
问题描述
这很难说,但我有一个包含容器视图的视图控制器(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).
推荐答案
您可以使用 prepareForSegue 当ContainerViewController成为子进程时,Vc1中的code>方法作为嵌入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;
}
}
编辑:次要代码修复
这篇关于在容器视图中的视图控制器中,如何访问包含容器的视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!