I’ve used this method on several apps that are for sale on the app store, but for some reason the current app I am working on is driving me nuts… I must be overlooking something.
The app’s main viewController .h file:
#import "MainMenuController.h"
#import "GamePlay.h"
@interface ProjectNameiPhoneViewController : UIViewController <MenuDelegate, GameDelegate> {
UIViewController *currentPageController;
}
The app starts up and loads the MainMenu viewController:
UIViewController *nextController = [[MainMenuController alloc] initWithNibName:@"MainMenuController" bundle:nil];
[nextController performSelector:@selector(setDelegate:) withObject:self];
[self.view addSubview:nextController.view];
currentPageController = nextController;
[currentPageController retain];
[nextController release];
From MainMenuController.m, the user chooses to start the game:
[delegate startGameplay:self];
Back in the app’s main viewController:
- (void)startGameplay:(MainMenuController *)sender {
UIViewController *nextController = [[GamePlay alloc] initWithNibName:@"GamePlay" bundle:nil];
[nextController performSelector:@selector(setDelegate:) withObject:self];
[currentPageController.view removeFromSuperview];
[self.view addSubview:nextController.view];
[currentPageController release];
currentPageController = nextController;
[currentPageController retain];
[nextController release];
}
From the gameplay screen, user hits the back button to return to the main menu:
- (IBAction)backTapped {
[delegate backToMenu:self];
}
Back in the app’s main viewController:
- (void)backToMenu:(GamePlay *)sender {
UIViewController *nextController = [[MainMenuController alloc] initWithNibName:@"MainMenuController" bundle:nil];
[nextController performSelector:@selector(setDelegate:) withObject:self];
[currentPageController.view removeFromSuperview];
[self.view addSubview:nextController.view];
[currentPageController release];
currentPageController = nextController;
[currentPageController retain];
[nextController release];
}
I once again choose to start the game from the main menu.
The GamePlay class/Nib loads, and I once again click the back button to return to the main menu.
At this point the app crashes, with no information printed to the console.
Any ideas would be GREATLY appreciated – I’ve commented out almost everything else in my code to the point where this switching between viewControllers is practically the only code being run and I’m at a loss as to why it is crashing…
Thanks so much in advance for your help!
This doesn’t seem like a true resolution but the app only crashes when I’m running it through Xcode’s “build and run.” If I open the app by clicking the icon on the device itself, the app runs perfectly. I can play it for long periods of time and mash the buttons to switch between view controllers over and over again very quickly, and it does not crash. So I’m going to submit it for the App Store even though it crashes every time without an error message when running through Xcode – it absolutely does not crash on the device itself.
The strangest part about the crash when running through Xcode is this:
The app crashes on the device, exiting out to the home screen. However, Xcode still shows the app as “Running” and I have the option to click “Stop” – it is not grayed out. As I said, no error message is printed to the console.