如何从子视图控制器访问父视图控制器的视图? [英] how can i access a parent view controller's view from a child view controller?

查看:137
本文介绍了如何从子视图控制器访问父视图控制器的视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主视图控制器,负责我的2D opengl ES视图的绘图,以及一个子视图控制器buttonManager,用于确定在启动过程中要加载和绘制的按钮。

I have a main view controller that takes care of the drawing for my 2D opengl ES view, and a child view controller buttonManager that determines what buttons to load and draw during launch.

一旦用户按下其中一个按钮,就会创建此视图控制器,并且应该显示其视图,但视图永远不会被添加但已经过测试才能工作。下面是来自主视图控制器的代码:

Once the user presses on one of these buttons, this view controller is created and its view is supposed to come up, but the view never gets added but has been tested to work. Heres my code from the main view controller:

 buttonManager=[[ButtonManager alloc] init];
 [self addChildViewController:buttonManager];
 [self.view addSubview:buttonManager.view];

并且我的代码启动此视图:

and heres my code to launch this view:

-(void)launchStopDialog: (NSString*)stopName {
    NSLog(@"stopdialog should be launched.");
    if (stopDialogController == nil)
        stopDialogController = [[StopDialogController alloc] initWithNibName:@"StopDialog" bundle:nil];
    if (stopDialogController)
        [stopDialogController presentWithSuperview:self.view.superview withStopName:stopName]; 
}


推荐答案

访问父View控制器你可以使用 self.parentViewController 。一旦拥有它,您只需使用其视图属性

To access the parent View controller you can use self.parentViewController. Once you have it you can access its view simply by using its view property

这篇关于如何从子视图控制器访问父视图控制器的视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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