排行榜未显示在cocos2d屏幕中

3
我使用下面的代码来显示排行榜,但是我只在控制台看到了以下内容。
cocos2d: surface size: 480x320

代码:

- (void)showLeaderboardForCategory:(NSString *)category
{
    // Only execute if OS supports Game Center & player is logged in
    if (hasGameCenter)
    {    

        // Create leaderboard view w/ default Game Center style
        GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];

        // If view controller was successfully created...
        if (leaderboardController != nil)
        {
            // Leaderboard config
            leaderboardController.leaderboardDelegate = self;   // The leaderboard view controller will send messages to this object
            leaderboardController.category = category;  // Set category here
            leaderboardController.timeScope = GKLeaderboardTimeScopeAllTime;    // GKLeaderboardTimeScopeToday, GKLeaderboardTimeScopeWeek, GKLeaderboardTimeScopeAllTime

            // Create an additional UIViewController to attach the GKLeaderboardViewController to
            myViewController = [[UIViewController alloc] init];

            // Add the temporary UIViewController to the main OpenGL view
            [[[CCDirector sharedDirector] openGLView] addSubview:myViewController.view];

            // Tell UIViewController to present the leaderboard
            [myViewController presentModalViewController:leaderboardController animated:YES];
        }
    }
}

最终,我像这样调用了代码:
    [[GameCenterManager sharedGameCenterManager] showLeaderboardForCategory:@"LeaderBoard"];

hasGameCenter 是全局变量吗?在这种情况下它可能是 false 值,因此不允许您进入吗? - Grady Player
@Grady Player:不是没有假的,因为我在它后面使用了CCLOG(@“..”)并将文本记录到控制台。 - Bobj-C
[CCDirector sharedDirector] openGLView能否返回nil? - Grady Player
1个回答

2
我找到了解决方案,我必须写下来:
    [[[[CCDirector sharedDirector] openGLView] window] addSubview:myViewController.view];

替代:

    [[[CCDirector sharedDirector] openGLView] addSubview:myViewController.view];

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接