I am in need of some help please. I have been stuck on this issue all day and I cannot find a fix. I will try and be as clear as possible with my problem.
I have 2 ViewControllers. One is called ViewController and the other is called GameViewController. In the ViewController I have my home screen menu and on the GameViewController I have the Game screen AND the Game Over screen. When you press play from ViewController it takes you to the Game, and then when you die you stay in the same GameViewController but in a Game Over view. If you press restart in the Game Over screen a segue takes you back modally to the Game Screen.
So here is the problem I am having.
When you die for the first time and go to the Game Over screen, you can click on home and it will take you home, BUT if you press restart, then die again (that's twice ) and then try to press home from the Game Over Screen it will NOT run the code inside the home button. The button actually works, I have an NSLog in their and it shows in the debugger screen. Weird I know. Please see below code that will show everything I have done to try and make this work.
In GameViewController.h //Above all the #imports
@class GameViewController;
@protocol GameViewControllerDelegate <NSObject>
-(void) GameViewControllerDidCancel:(GameViewController *)controller;
- (IBAction)homeBtn:(id)sender;
@end
And this just after the the close } in @Interface
@property (nonatomic, weak) id <GameViewControllerDelegate> delegate;
In GameViewController.m after the @Implementation
@synthesize delegate = _delegate;
And this in my homeBtn
- (IBAction)homeBtn:(id)sender {
NSLog(@"home btn pressed");
[self.delegate GameViewControllerDidCancel:self];
}
Then in my ViewController.h
#import "GameViewController.h"
@interface ViewController : UIViewController <GameViewControllerDelegate>
ViewController.m
When I press play
- (IBAction)playButton:(id)sender {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
UIStoryboard* sb = [UIStoryboard storyboardWithName:@"Main_iPad"
bundle:nil];
GameViewController* controller= [sb instantiateViewControllerWithIdentifier:@"GML"];
controller.delegate = self;
[self presentViewController:controller animated:NO completion:nil];
[audioPlayer stop];
}else {
UIStoryboard* sb = [UIStoryboard storyboardWithName:@"Main_iPhone"
bundle:nil];
GameViewController* controller= [sb instantiateViewControllerWithIdentifier:@"GML"];
controller.delegate = self;
[self presentViewController:controller animated:NO completion:nil];
[audioPlayer stop];
}
}
And the method that I try to call from my homeBtn is also in here
#pragma mark - GameViewControllerDelegate
- (void) GameViewControllerDidCancel:(GameViewController *)controller {
[self dismissViewControllerAnimated:NO completion:nil];
}
I am pretty sure that is it. So like I said before, the restart button is just linked to a segue to return back to the Game screen.
Please guys, I am really desperate now, I am completely out of ideas.
Thank you