jfisk jfisk - 1 year ago 66
iOS Question

how can i access a parent view controller's view from a child view controller?

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];

aqs aqs
Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download