Search code examples
objective-cios7delegatesleaderboard

Done button in game center leader-board doesn't work


When i press done button in leaderboard view, it doesn't do anything and leaderboard is still visible.

here is code:

GKGameCenterViewController *gcViewController = [[GKGameCenterViewController alloc] init];

gcViewController.gameCenterDelegate = self;
[gcViewController setDelegate:self ];
if (shouldShowLeaderboard) {
    gcViewController.viewState = GKGameCenterViewControllerStateLeaderboards;
    gcViewController.leaderboardIdentifier = currentLeaderBoard;
}
else{
    gcViewController.viewState = GKGameCenterViewControllerStateAchievements;
}

[self presentViewController:gcViewController animated:YES completion:nil];**

Solution

  • you must add the function to dismiss the view controller (to delegate)

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

    }