2

I'm trying to make a leaderboard for a game I created using SpriteBuilder. I have the following code.

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

However, on the UIViewController *vc line, I keep getting the following error, "Property 'view' not found on object of type 'MainScene *'.

I have been searching for hours, does anyone know of a solution for this?

James Webster
  • 31,873
  • 11
  • 70
  • 114
Jude Michael Murphy
  • 1,198
  • 2
  • 12
  • 23

2 Answers2

3

MainScene does not have a view property because it isn't a UIViewController. There is only one UIViewController in a Cocos2d application and that is the CCDirector.

If you want to present a view controller you need to present it from the CCDirector:

 [[CCDirector sharedDirector] presentViewController:vc animated:YES completion:nil];
Ben-G
  • 4,996
  • 27
  • 33
0

I actually answered my own question! :D

UIViewController *vc = [[[[CCDirector sharedDirector] view] window] rootViewController];
Jude Michael Murphy
  • 1,198
  • 2
  • 12
  • 23
  • actually this can be condensed to: [CCDirector sharedDirector] (CCDirector is cocos2d's UIViewController) – CodeSmile Mar 06 '14 at 11:20