Apologies for the long post and I hope it makes some sense to someone out there.
I have written an iPhone game (in Quartz 2d) which uses the following structure :
This all works fine. I am now trying to integrate a Main Menu for the game. So far I have done the following :
So far so good - pressing the "start" button starts the game. But.....
The problem is now that I can't find a way for the Game Controller to call up the Main Menu class (e.g for when game is over). I can't use "self dismissModalViewController" as Game Controller is an NSObject class and not a view controller. How can I get the Game Controller to pull up my Main Menu ?
Thanks all for reading,
Martin
If you have your menu object still living just call its "dissmisModalViewController". for example [[MainMenu getInstance] dismissModalViewControllerAnimated:YES]; where getInstance returns your object or have it stored in GameController as property, so when you create GameController from your MainMenu or GameViewController just assign itself as his property gameInstance.mainMenu = self;
How-to make getInstance method:
You could either use Singleton pattern ( you can get one from apple dev site ) or if you manually create MainMenu you could just remember self in some global variable and getInstance would be class method, something like that:
@interface MainMenu : UIViewController
{
}
+ (MainMenu*) getInstance;
@end
and in implementation
MainMenu *singleInstance;
@implementation MainMenu
- (id)init
{
if((self = [super init]))
{
singleInstance = self;
} return self;
}
+ (MainMenu*)getInstance
{
return singleInstance;
}
@end;
Hope this helps,
Krzysztof Zabłocki