0

I am trying to show a Leader-board in my Cocos2d Game. The code below works correctly on iOS 5.0. However on 6.1 it crashes with the error message below. Thanks in advance for any suggestions.

* Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'A view can only be associated with at most one view controller at a time! View > is associated with . Clear this association before associating this view with .'

- (void)showLeaderboard:(id)sender
{
GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
if (leaderboardController != NULL)
{

    leaderboardViewController = [[UIViewController alloc] init];
    leaderboardController.category = self.currentLeaderBoard;
    leaderboardController.leaderboardDelegate = self;

    [leaderboardViewController setView:[[CCDirector sharedDirector] openGLView]];
    [leaderboardViewController presentViewController:leaderboardController animated:YES completion:nil];

}
}

- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
{
[leaderboardViewController dismissViewControllerAnimated:YES completion:nil];
[viewController release];
}
4

1 回答 1

1

尝试停止 openGL 动画并恢复。

-(void)showLeaderboard
{
        [[CCDirector sharedDirector] stopAnimation];

         GKLeaderboardViewController *leaderboardViewController = [[[GKLeaderboardViewController alloc] init] autorelease];
         leaderboardViewController.leaderboardDelegate = self;

         AppController *app=(AppController*)[UIApplication sharedApplication].delegate;
         [app.navController presentModalViewController:leaderboardViewController animated:YES];
}


-(void) leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
{
    AppController *app=(AppController*)[UIApplication sharedApplication].delegate;
    [app.navController  dismissModalViewControllerAnimated:YES];

    [[CCDirector sharedDirector] startAnimation];
}
于 2013-05-20T04:10:14.423 回答