1

在他们的支持OpenFeint给你这个,但我不太明白。如何获取排行榜数据,比如前 10 名并在我自己的 UI 中显示?

原文链接:http ://www.openfeint.com/ofdeveloper/index.php/kb/article/000028

[OFHighScoreService getPage:1 forLeaderboard:@"leaderboard_id_string" friendsOnly:NO silently:YES onSuccess:OFDelegate(self, @selector(_scoresDownloaded:)) onFailure:OFDelegate(self, @selector(_failedDownloadingScores))];

- (void)_scoresDownloaded:(OFPaginatedSeries*)page
{
    NSMutableArray* highscores = nil;

    if ([page count] > 0)
    {
        if ([[page objectAtIndex:0] isKindOfClass:[OFTableSectionDescription class]])
        {
            // NOTE: In the following line, we access "[page objectAtIndex:1]" to retrieve high scores from
            // the global leaderboard.  Using "[page objectAtIndex:0]" would retrieve scores just for the local player.
            // Older versions of OpenFeint did not break this out into 2 sections.
            highscores = [(OFTableSectionDescription*)[page objectAtIndex:1] page].objects;
        }
        else
        {
            highscores = page.objects;
        }
    }

    for (OFHighScore* score in highscores)
    {
        // ...
    }
}
- (BOOL)canReceiveCallbacksNow
{
    return YES;
} 
4

1 回答 1

2

请求高分页面的代码是第一行,即:

[OFHighScoreService getPage:1 forLeaderboard:@"leaderboard_id_string" friendsOnly:NO silently:YES onSuccess:OFDelegate(self, @selector(_scoresDownloaded:)) onFailure:OFDelegate(self, @selector(_failedDownloadingScores))];

您将此行放在要开始查询高分的地方。您可以根据需要更改页码。一旦检索到高分页面,_scoresDownloaded就会调用回调。该示例向您展示了如何遍历数组OFHighScore中的对象。您可以用自己的代码highscores替换注释,以向玩家显示分数,或其他任何内容。// ...

(如果_failedDownloadingScores调用错误;您应该实现它以显示错误。)

于 2010-08-27T23:41:18.227 回答