我有这个代码用于在视图中显示排行榜
·H
UIViewController *presentingViewController;
{
@property (retain) UIViewController *presentingViewController;
的.m
- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
{
[presentingViewController dismissModalViewControllerAnimated:YES];
[self.presentingViewController.view removeFromSuperview];
}
- (void)leaderboard
{
GKLeaderboardViewController *lb = [[GKLeaderboardViewController alloc] init];
if(lb != nil){
lb.leaderboardDelegate = self;
presentingViewController = [[UIViewController alloc] init];
[[[[CCDirector sharedDirector] openGLView] window] addSubview:presentingViewController.view];
[presentingViewController presentModalViewController:lb animated:YES];
}
evey东西炒得很好,它显示了leadeboard,当我点击完成按钮它会消失,但是我点击了游戏中心按钮,排行榜没有出来,我们也无法浏览其他页面。< / p>我的上述代码的问题是什么,这适用于iphone cocos2d app
提前致谢。
答案 0 :(得分:1)
我在cocos2D游戏中使用了这段代码并且工作正常,
-(void)displayLeaderboard
{
GKLeaderboardViewController *leaderboardViewController = [[GKLeaderboardViewController alloc] init];
leaderboardViewController.leaderboardDelegate = self;
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
[app.navController presentModalViewController:leaderboardViewController animated:YES];
}
#pragma mark GameKit delegate
-(void) achievementViewControllerDidFinish:(GKAchievementViewController *)viewController
{
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
[app.navController dismissModalViewControllerAnimated:YES];
}
-(void) leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
{
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
[app.navController dismissModalViewControllerAnimated:YES];
}