Cannot dismiss GKGameCenterViewController presented from SKScene

你。 提交于 2020-01-06 08:43:10

问题


I'm presenting a GKGameCenterViewController from an SKScene. This is my code:

-(void)showLeaderboardAndAchievements:(BOOL)shouldShowLeaderboard{
    GKGameCenterViewController *gcViewController = [[GKGameCenterViewController alloc] init];
    gcViewController.viewState = GKGameCenterViewControllerStateLeaderboards;
    gcViewController.leaderboardIdentifier = _leaderboardIdentifier;

    // _spriteViewController references an UIViewController
    [_spriteViewController presentViewController:gcViewController animated:YES completion:nil];
}

I don't have problems presenting the window, however I cannot manage to let users close it. I implemented the method gameCenterViewControllerDidFinish however the function is not called at all. What do I have to do so users can close the leaderboard?


回答1:


I fixed by adding the line gcViewController.gameCenterDelegate = _spriteViewController;

-(void)showLeaderboardAndAchievements:(BOOL)shouldShowLeaderboard{
    GKGameCenterViewController *gcViewController = [[GKGameCenterViewController alloc] init];
    gcViewController.viewState = GKGameCenterViewControllerStateLeaderboards;
    gcViewController.leaderboardIdentifier = _leaderboardIdentifier;
    gcViewController.gameCenterDelegate = _spriteViewController; // er

    // _spriteViewController references an UIViewController
    [_spriteViewController presentViewController:gcViewController animated:YES completion:nil];
}

While it worked I got the warning: Assigning to 'id<GKGameCenterControllerDelegate>' from incompatible type 'UIViewController *__weak'

For anyone in this situation the problem was simply that _spriteViewController was of typeUIViewController, changing that to my custom class fixed the issue. You can also declare the property referencing the ViewController like this:

UIViewController <GKGameCenterControllerDelegate> *_spriteViewController;


来源:https://stackoverflow.com/questions/24688134/cannot-dismiss-gkgamecenterviewcontroller-presented-from-skscene

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!