Swift - FirstViewController和GKGameCenterControllerDelegate

时间:2015-04-04 15:29:20

标签: swift game-center

我想在我的应用中加入GameCenter排行榜,但我遇到了一个问题。

当我想要显示LeaderBoard时,我使用此代码:

//shows leaderboard screen
func showLeader() {
    var vc = self.view?.window?.rootViewController
    var gc = GKGameCenterViewController()
    gc.gameCenterDelegate = self
    vc?.presentViewController(gc, animated: true, completion: nil)
}

为此,我必须在我的班级中使用GKGameCenterControllerDelegate:

class FirstViewController: UIViewController, GKGameCenterControllerDelegate {

当我这样做时,我有一个错误:'键入FirstViewController'不符合协议' GKGameCenterControllerDelegate'。

任何解决方案?

1 个答案:

答案 0 :(得分:1)

您需要包含以下方法:

 func gameCenterViewControllerDidFinish(gcViewController: GKGameCenterViewController!)
    {
        // By tapping on Done, the Game Center window will be dismissed.
        self.dismissViewControllerAnimated(true, completion: nil)
    }

此处有更多信息:https://developer.apple.com/library/mac/documentation/GameKit/Reference/GKGameCenterViewControllerDelegate_Ref/