2

我正在尝试为使用 SpriteBuilder 创建的游戏制作排行榜。我有以下代码。

if (gameCenterController != nil)
{
    gameCenterController.gameCenterDelegate = self;
    gameCenterController.viewState = GKGameCenterViewControllerStateLeaderboards;
    UIViewController *vc = self.view.window.rootViewController;
    [vc presentViewController: gameCenterController animated: YES completion:nil];
}

但是,在 UIViewController *vc 行上,我不断收到以下错误,“在 'MainScene *' 类型的对象上找不到属性 'view'。

我一直在寻找几个小时,有没有人知道这个解决方案?

4

2 回答 2

3

MainScene没有view属性,因为它不是UIViewController. Cocos2d 应用程序中只有一个UIViewController,那就是CCDirector.

如果要呈现视图控制器,则需要从以下位置呈现它CCDirector

 [[CCDirector sharedDirector] presentViewController:vc animated:YES completion:nil];
于 2014-02-25T19:31:50.600 回答
0

我实际上回答了我自己的问题!:D

UIViewController *vc = [[[[CCDirector sharedDirector] view] window] rootViewController];
于 2014-02-27T00:35:56.393 回答