解雇GKGameCenterViewController

问题描述:

我会演示我的问题是这样的:我有一个项目与2类 - ViewController和GCManage。解雇GKGameCenterViewController

该ViewController是UIViewController和GCManage的NSObject的子类。

当我的ViewController按下一个按钮,它会调用这个方法:

-(IBAction)showLeaderboards:(id)sender{ 
    GCManage *manageGC = [[GCManage alloc] init]; 
    if (manageGC.isGCenabled == YES){ 
     GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc] init]; 
     if (gameCenterController != nil) 
     { 
      gameCenterController.gameCenterDelegate = manageGC; 
      gameCenterController.viewState = GKGameCenterViewControllerStateLeaderboards; 
      [self presentViewController:gameCenterController animated:YES completion:nil]; 
     } 
    } 
} 

对于这种情况下,假定isGCenabled = YES

现在GCManage接口是

@interface GCManage : NSObject <GKGameCenterControllerDelegate>(以h文件中,第一线)。

我实现

- (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)gameCenterViewController 
{ 
[gameCenterViewController.presentingViewController dismissViewControllerAnimated:YES completion:^(void){}]; 
[gameCenterViewController.presentedViewController dismissViewControllerAnimated:YES completion:^(void){}]; 
[gameCenterViewController dismissViewControllerAnimated:YES completion:^(void){}]; 
NSLog(@"Ran"); 
} 

在GCManage但它不会出现在任何情况下被调用。

现在当视图控制器是委托并实现

- (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)gameCenterViewController 
{ 

[gameCenterViewController.presentingViewController dismissViewControllerAnimated:YES completion:^(void){}]; 
NSLog(@"Ran"); 
} 

它运行完美。这里发生了什么事?

+0

在GCManage.h中,你是否#import # 和'#import '?您说您的GCManage定义位于.h文件的第一行。 – stevekohls

+0

当然。我使用xcode创建并导入:#import #import @interface GCManage:NSObject

ViewController中为您的GCManage对象创建属性。在showLeaderboards:中创建的对象manageGC未被保留,因此委托函数从不被调用。

+0

老兄,您真棒。 –

+0

很高兴我能帮到你。感谢你的接纳。 – stevekohls

+0

调用presentViewController将保留它 – jjxtra