-1

我的第一个屏幕上有一个用于加载小游戏的按钮,代码如下:

- (IBAction)playButtonPressed:(id)sender
 {

[self startGameWithConfig:[RootViewController singleplayerGameConfig]];

        NSLog(@"play again");

 }

在我的游戏页面内部,当我使用此按钮时,我有一个返回第一个屏幕的按钮,我可以返回但我的 playButtonPressed 不再工作,它打印 NSLog 但按钮不再加载游戏

这是我的返回按钮:

- (IBAction)return:(id)sender {

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

}

你能帮我实现这个吗

提前致谢!

这是我的 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];

                 }];
}
4

1 回答 1

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];

于 2013-02-06T15:42:38.143 回答