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];
}