views:

194

answers:

1

Hey guys I need some help with this:

I have two view controllers, let's say:

  • FirstViewController (first) is inside a navigationviewcontroller
  • SecondViewController (second)

So in the first's viewDidLoad method I have this:

SecondViewController *second = [[SecondViewController alloc] initWithNibName:...];

[self.addsubview:second.view];

I've done this cuz I want to make my custom tab bar with my custom buttons and colors.

I have this when I press one of the buttons of my custom "tab bar" (seconviewcontroller)

ConfiguracionViewController *conf = [[ConfiguracionViewController alloc] initWithNibName:@"ConfiguracionView" bundle:nil];

[self.navigationController pushViewController:conf animated:YES];
[conf release];

but because the second view controller is not pushed or modal presented in the first view controller I can't acces the navigationController. I've tried also with this

[self.parentViewController.navigationController pushViewController:...];

But it didn't work either.

Please help me out, I need to learn how to do that and sorry for my bad english.

Best Regards,
Carlos Vargas

+1  A: 

First, shouldn't you be adding the second view to the first view like this:

[self.view addSubview:second.view];

The property parentViewController will not work in this case since second is not part of a navigation hierarchy.

Instead, you can make your own property that references the "parent" view controller:

SecondViewController *second = [[SecondViewController alloc] initWithNibName:...];

// set new property
second.parentVC = self;

[self.view addSubview:second.view];

In SecondViewController.h you need to declare the instance variable and property for "parentVC" and in SecondViewController.m you need to synthesize the property.

Then, you should be able to access the navigation controller and push a view controller from SecondViewController.m like this:

[self.parentVC.navigationController pushViewController:...];
gerry3
Thanks it worked!
Carlos Vargas