UIButton第二次没有工作(Objective-C)

时间:2013-02-05 20:19:42

标签: objective-c ipad uiviewcontroller uibutton presentmodalviewcontroller

我在第一个屏幕上有一个按钮,用于加载一个小游戏,这里是代码:

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

                 }];
}

1 个答案:

答案 0 :(得分:0)

我很难理解这段代码的位置,因为没有标题但看起来当你试图回到RootViewController时,你正在创建一个新代码并将其推送到堆栈上。您希望确保删除了topViewController,而不是添加更多视图。

首先尝试替换return方法:

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

用这个:

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

我不确定您是如何设置视图层次结构的,但是如果您有一个有效的navigationController而不是尝试使用[self.navigationController popNavigationController:YES];