解雇GKGameCenterViewController

时间:2013-08-20 12:00:33

标签: uiviewcontroller gamekit

我会像这样展示我的问题:我有一个包含2个类的项目--ViewController和GCManage。

ViewController是UIViewController的子类和NSObject的GCManage。

当我在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中,但似乎无论如何都不会被调用。

现在,当ViewController是委托和实现

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

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

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

1 个答案:

答案 0 :(得分:1)

ViewController对象的GCManage中创建一个属性。您manageGC中创建的showLeaderboards:对象未被保留,因此永远不会调用委托函数。