views:

22

answers:

1

I've been attempting to figure this out for a while now, but I'm up to a point where I can't seem to solve my problem from reading other Q&As. I'm trying to get the active UIViewController in a UINavigationController to send popViewController/pushViewController messages to the UINavigationController, but I cannot figure it out. I'm probably doing something rather stupid that is causing it to break. The structure should be like this, but even then I'm not sure if I've done that right.

  • mainController
    • primaryNavigationController
      • firstViewController
      • secondViewController

both firstViewController and secondViewController are a subclass

mainController.m

 firstViewController = [[FirstTestViewController alloc] init];
 secondViewController = [[FirstTestViewController alloc] init];


 primaryNavigationController = [[UINavigationController alloc]
           initWithRootViewController:firstViewController];
 [primaryNavigationController.view setFrame:CGRectMake(0,0,320i,409)];
 [self.view addSubview:[primaryNavigationController view]];
 [primaryNavigationController.navigationBar setFrame:CGRectMake(0,0,20,44)];
 primaryNavigationController.navigationBar.tintColor = [UIColor blackColor];

How can I tell primaryNavigationController to push/pop a VC from within the firstTestViewController subclass?

+1  A: 

You would allocate the second view controller within your first view controller (because you don't need it before):

secondViewController = [[FirstTestViewController alloc] init];
[self.navigationController pushViewController:secondViewController animated:YES];
[secondViewController release];

The SDK includes many sample projects that involve a navigation controller and show you how to do this.

Ole Begemann
Thanks very much, this was exactly what I was looking for. My issue was that I was adding [self.primaryNavigationController rather than [self.navigationController.
Dylan Marshall