---
title: "Game Center show multiple leaderboards:"
author: "frank__wang"
date: "2014-04-18T09:24:04Z"
tags: []
categories: ["移动开发"]
slug: "game-center-show-multiple-leaderboards"
draft: false
lastmod: "2014-04-18T09:30:56Z"
id: 2048130
url: "https://frank--wang.iteye.com/blog/2048130"
---

(转自 stackoverflow)  http://stackoverflow.com/questions/22974453/game-center-sandbox-mode-display-multiple-leaderboards

最近项目中遇到在gamecenter中显示 多个 排行榜 的问题，但是按照**ABGameKitHelper**   
的方法，只能显示单个排行榜，然后点击左上角的按钮才能显示多个排行版，通过查z资料在 stackoverflow上找到了解决办法，特此mark一下 。 感谢大家的帮助。

 

\- (void) showGameCenter{  
    if (!\[\[ABGameKitHelper sharedHelper] hasConnectivity]) return;

    //Check if device runs on iOS 5  
    if(\[\[\[UIDevice currentDevice]systemVersion]intValue]==5)  
    {  
        //If so, we must use the GKLeaderboardViewController  
        GKLeaderboardViewController \*leaderboard = \[\[GKLeaderboardViewController alloc] init];

        if (leaderboard != nil)  
        {  
            leaderboard.leaderboardDelegate = self;  
            \[\[self topViewController] presentViewController:leaderboard animated:YES completion:nil];  
        }

    }else if (\[\[\[UIDevice currentDevice]systemVersion]intValue]&gt;=6)  
    {  
        //if it runs on iOS 6 or higher, we use GKGameCenterViewController  
        GKGameCenterViewController \*gameCenterController = \[\[GKGameCenterViewController alloc] init];

        if (gameCenterController != nil)  
        {  
            gameCenterController.gameCenterDelegate = self;  
            gameCenterController.viewState = GKGameCenterViewControllerStateDefault;

            \[\[self topViewController] presentViewController:gameCenterController animated:YES completion:nil];  
        }  
    }  
}

And don't forget to add :

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

Using this function will allow you to show a nice view containing all your leaderboards and achievements.