views:

89

answers:

1

Hi all,

I seem to have a problem switching between 2 UINavigationControllers, i.e. one which controls the main (selection) menu of my application, and the second which controls the main session (i.e. the user can't go back to the selection menu once they're started a new session).

The first works just fine, but I get into trouble when trying to load the second. I have a class called GameViewController which contains the second UINavigationController instance. I set this up as usual, linking it as an IBOutlet to the delegate and setting up the NavController in the GameViewController.xib file with its 'Class' property pointing at GameScreenViewController (my main game screen), and its NIB Name property pointing to the GameScreenViewController nib file. I then create a new instance of GameViewController and load it.

In IB, the navigation controller looks fine, with its View 'loaded from "GameScreenViewController"', however when the NavigationController is loaded in the game, it actually loads the GameViewController's UIWindow instance (just a blank window).

I'm not sure how to make it load the Navigation Controller's view rather than its own window?

Also, another quick question. When I load the second navigation controller from the first, which makes more sense to use:

[self.view addSubview:gameViewController.view];

or

[self presentModalViewController:gameViewController animated:YES];

Thanks for any help, much appreciated :D

Michael

A: 

Ok so a slight update - I've decided to create the second UINavigationController programatically rather than add it to its own nib. So I removed the class and the nib file that containted the Navigation Controller object and have added the following code to the class that creates the new Navigation Controller. This class incidentally is a view in the stack of the first controller:

GameScreenViewController *gameScreenViewController = [[GameScreenViewController alloc] init];

UINavigationController *newNavController = [[UINavigationController alloc]initWithRootViewController:gameScreenViewController];

[gameScreenViewController release];

self.gameNavController = newNavController;

[newNavController release];

[self presentModalViewController:gameNavController animated:YES];

But when I run the program, it crashes when I try to load the new view controller with the error

* Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key gameNavController.'

Is there something I need to do with the GameScreenViewController to make this work?

Thanks!

Michael

Smikey