Code:
- (IBAction)mainMenuTouched {
MainMenu *mainView = [[MainMenu alloc] initWithNibName:@"MainMenu" bundle:[NSBundle mainBundle]];
[self.view addSubview:mainView.view];
//[Game release];
}
Within the scope of the code you gave, releasing
Game does not make sense... I suggest removing this statement, as it is likely a global variable and should be set to
nil and
released in
viewDidUnload: and
dealloc: . The way you have implemented it, [Game release] is not doing anything, per se. Maybe you meant
[mainView release]; ?
If the code snippet you gave it indeed responsible for going from the Game screen to the Main Menu, then you have not actually stopped the Game viewController, and are actually stacking another view on top of it, via [self.view addSubview:mainView.view]. To prove this to you... add [self.view removFromSuperview:mainView.view]; and you will go back to the game...
like so:
Code:
- (IBAction)mainMenuTouched {
MainMenu *mainView = [[MainMenu alloc] initWithNibName:@"MainMenu" bundle:[NSBundle mainBundle]];
[self.view addSubview:mainView.view];
[self.view removFromSuperview:mainView.view]; // THIS LINE 'UNDOES' THE PREVIOUS LINE'S CODE....
//[Game release];
[mainView release]; // PERHAPS THIS IS WHAT YOU MEANT TO SAY INSTEAD OF [Game release];
}
I suggest you create a 'dummy' "Utility Application" in XCode and see how it handles the transition between 2 view controllers (which is via lazy loading...), as this is how you can have 2 view controllers in memory at the same time. However, you will likely need to implement more code to go from 1 view controller to another, such as transferring variables (scores? level? time?) to the next view (this can be done in multiple ways... via code, an intermediate file (think plist) or other data storage method, stopping the game and music, and removing the view at the end.
The warning you are getting is not occurring in the code you provided, but may be related to how you are removing your 'view'... post the code where the Warning occurs, but I am guessing it is one of those warnings you can ignore if you are doing it correctly...
Good Luck.