我想在我的Cocos2d游戏中展示一个领导者板块。以下代码在iOS 5.0上正常运行。但是在6.1上它会崩溃并显示以下错误消息。在此先感谢您的任何建议。
* 由于未捕获的异常'UIViewControllerHierarchyInconsistency'而终止应用程序,原因:'视图一次最多只能与一个视图控制器关联!查看>与....关联 。在将此视图与。'
关联之前,请清除此关联- (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];
}
答案 0 :(得分: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];
}