我在设置游戏中心排行榜时遇到了问题,因为我收到错误Cannot assign a value of type 'ViewController' to a value of type 'GKGameCenterControllerDelegate!'
。我认为它与我放在顶部的代码有关:
class ViewController: UIViewController, GKGameCenterControllerDelegate, ADBannerViewDelegate {
//stuff
}
以及我在其中一个操作按钮中输入的代码:
//shows leaderboard screen
func showLeader() {
var vc = self.view?.window?.rootViewController
var gc = GKGameCenterViewController()
gc.gameCenterDelegate = self //<------This is the problem child.
vc?.presentViewController(gc, animated: true, completion: nil)
}
发生了什么事?谢谢!
答案 0 :(得分:3)
您收到此错误是因为ViewController
不符合协议GKGameCenterControllerDelegate
。
要解决此问题,请将此GKGameCenterControllerDelegate
的委托方法添加到ViewController
类中:
func gameCenterViewControllerDidFinish(gameCenterViewController: GKGameCenterViewController!){
gameCenterViewController.dismissViewControllerAnimated(true, completion: nil)
}
你的错误将会解决。