2012-10-06 227 views
1

我有在視圖中遊戲中心集成iphone

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

}

埃維事情炒鍋排行榜顯示該代碼很好,它顯示了leadeboard,當我點擊完成按鈕它會消失,但我很喜歡遊戲中心按鈕,領導者董事會不出來,我們也無法通過其他網頁瀏覽。

什麼是我上面的代碼problm,這是iphone cocos2d的應用

在此先感謝。

回答

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