-1

I have a button in my first screen for loading a small game here is the code:

- (IBAction)playButtonPressed:(id)sender
 {

[self startGameWithConfig:[RootViewController singleplayerGameConfig]];

        NSLog(@"play again");

 }

and inside of my game page I have a button to back to the first screen when I used this button I can back but my playButtonPressed not working any more, it print the NSLog but the button it's not loading the game any more

here is my return button:

- (IBAction)return:(id)sender {

RootViewController *b = [[RootViewController alloc] init];
[self presentModalViewController:b animated:YES];

}

would you please help me to this implementation

Thanks in advance!

and here is my startGamingWithConfig

- (void) startGameWithConfig:(GameConfig *)config
{
// fade in the loading screen to hide load time
[_loadingView setHidden:NO];
[_loadingView setAlpha:0.0f];
[UIView animateWithDuration:0.2f
                      delay:0.0f
                    options:UIViewAnimationOptionCurveLinear
                 animations:^{
                     [_loadingView setAlpha:0.0f];
                 }
                 completion:^(BOOL finished){
                     CardsViewCtrl* newController = [[CardsViewCtrl alloc] init];
                     newController.gameConfig = config;
                     AppDelegate *delegate = (AppDelegate *)[[UIApplication 
sharedApplication] delegate];
                     [delegate.navController pushFadeInViewController:newController 
animated:YES];

                 }];
}
  • I believe you want to "self dismissModalViewController..." in your return method. Also I believe return is a reserved word in Objc-C so at the least it probably is not a good idea to call a method just **return** – Firo Feb 05 '13 at 22:27
  • @Joel would you please let me know what should i have and where –  Feb 06 '13 at 14:37
  • I added an answer, let me know if that suffices, otherwise what is not working. – Firo Feb 06 '13 at 15:43

1 Answers1

0

It is a bit hard for me to understand where this code is since there are no headings but it looks like when you are attempting to go back to the RootViewController you are creating a new one and pushing that on the stack. You want to make sure that your topViewController is removed, not adding more views.

So for a starter try to replace return method:

- (IBAction)return:(id)sender {
    RootViewController *b = [[RootViewController alloc] init];
    [self presentModalViewController:b animated:YES];
}

with this:

- (IBAction)goBack:(id)sender {
    [self dismissModalViewController];
}

I am not sure how you have your view hierarchy setup, but if you have a working navigationController than try using [self.navigationController popNavigationController:YES];

Firo
  • 15,448
  • 3
  • 54
  • 74
  • I updated my answer. Just literally replace your `return` method with the one I gave you. Make sure you change your IBAction plug too. Let em know if you still do not understand or want more information. – Firo Feb 06 '13 at 20:47