从容器视图的视图控制器中,如何访问包含容器的视图控制器?

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).

推荐答案

您可以使用 Vc1 中的 prepareForSegue 方法,因为将 ContainerViewController 设为子级时会发生嵌入 segue.您可以将 self 作为 obj 传递或存储对孩子的引用以供以后使用.

You can use the prepareForSeguemethod 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;
    }
}

次要代码修复

这篇关于从容器视图的视图控制器中,如何访问包含容器的视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)