无法关闭游戏中心排行榜页面

时间:2014-08-29 23:42:02

标签: ios objective-c cocoa-touch game-center

我可以毫无问题地加载排行榜。但是,当“完成”时,我无法将其关闭。单击按钮。

我如何打开它:

- (IBAction)leaderboardsClicked:(id)sender{
    if ([GKLocalPlayer localPlayer].isAuthenticated) {
        GKGameCenterViewController *leaderboardController = [[GKGameCenterViewController alloc] init];
        [self presentViewController:leaderboardController animated:YES completion:NULL];
    }else{
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Error"
            message: @"You must be logged into Game Center to view the leaderboards. Open Game Center?"
            delegate: self
            cancelButtonTitle:@"No"
            otherButtonTitles:@"Yes",nil];
        [alert show];
    }
}

我如何关闭它:

- (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)gameCenterViewController{
    NSLog(@"test");
    [self dismissViewControllerAnimated:YES completion:nil];
}

修改

该方法根本不运行;所以"测试"甚至不打印。

我将<GKGameCenterControllerDelegate>添加到我的ViewController协议中。

1 个答案:

答案 0 :(得分:2)

请改为尝试:

- (IBAction)leaderboardsClicked:(id)sender{
    if ([GKLocalPlayer localPlayer].isAuthenticated) {
        GKGameCenterViewController *leaderboardController = [[GKGameCenterViewController alloc] init];
        leaderboardController.gameCenterDelegate = self;
        gameCenterController.viewState = GKGameCenterViewControllerStateLeaderboards;

        [self presentViewController:leaderboardController animated:YES completion:NULL];
    }else{
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Error"
            message: @"You must be logged into Game Center to view the leaderboards. Open Game Center?"
            delegate: self
            cancelButtonTitle:@"No"
            otherButtonTitles:@"Yes",nil];
        [alert show];
    }
}

- (void) gameCenterViewControllerDidFinish:(GKGameCenterViewController*) gameCenterViewController {
    [self dismissViewControllerAnimated:YES completion:nil];
}