Objective c UIButton第二次不工作(目标C)

Objective c UIButton第二次不工作(目标C),objective-c,ipad,uiviewcontroller,uibutton,presentmodalviewcontroller,Objective C,Ipad,Uiviewcontroller,Uibutton,Presentmodalviewcontroller,我在第一个屏幕上有一个按钮,用于加载一个小游戏。下面是代码: - (IBAction)playButtonPressed:(id)sender { [self startGameWithConfig:[RootViewController singleplayerGameConfig]]; NSLog(@"play again"); } 在我的游戏页面中,我有一个按钮,当我使用这个按钮时,我可以返回到第一个屏幕,但我的PlayButton被按下不再工作,它会打印NSL

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

- (IBAction)playButtonPressed:(id)sender
 {

[self startGameWithConfig:[RootViewController singleplayerGameConfig]];

        NSLog(@"play again");

 }
在我的游戏页面中,我有一个按钮,当我使用这个按钮时,我可以返回到第一个屏幕,但我的PlayButton被按下不再工作,它会打印NSLog,但是 按下按钮,不再加载游戏了

这是我的返回按钮:

- (IBAction)return:(id)sender {

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

}
你能帮我完成这个任务吗

提前谢谢

这是我对配置的开始

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

                 }];
}

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

因此,对于初学者,尝试替换
返回
方法:

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

我相信您希望在返回方法中使用“self dismissModalViewController…”。而且我相信return在Objc-C中是一个保留字,所以至少调用一个方法可能不是一个好主意return@Joel请让我知道我应该有什么以及我在哪里添加了一个答案,让我知道这是否足够,否则什么是无效的。我更新了我的答案。只需用我给你的
return
方法替换你的
return方法。确保您也更换了IBAction插头。如果您仍然不理解或需要更多信息,请告知em。