gpt4 book ai didi

ios - 显示游戏中心排行榜无法快速工作

转载 作者:行者123 更新时间:2023-11-28 09:08:38 25 4
gpt4 key购买 nike

我正在快速编码,我从我的提交按钮收到以下错误消息。排行榜没有出现在模拟器中,只是给我下面的错误信息

<GKGameCenterViewController: 0x7a8d0800> on     <Chinese_Quiz.OpeningViewController: 0x78688aa0> whose view is not in the  window hierarchy!

以下是我应用中的所有游戏中心代码。

  override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
Randomize()
Hide()
authenticateLocalPlayer()

}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func Submit(sender: AnyObject) {
saveHighscore(Score)
showLeaderboard()

}

func authenticateLocalPlayer(){

var localPlayer = GKLocalPlayer.localPlayer()

localPlayer.authenticateHandler = {(viewController, error) -> Void in

if (viewController != nil) {
self.presentViewController(viewController, animated: true, completion: nil)
}

else {
println((GKLocalPlayer.localPlayer().authenticated))
}
}

}

func gameCenterViewControllerDidFinish(gameCenterViewController: GKGameCenterViewController!)
{
gameCenterViewController.dismissViewControllerAnimated(true, completion: nil)

}

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



func saveHighscore(score:Int) {

//check if user is signed in
if GKLocalPlayer.localPlayer().authenticated {

var scoreReporter = GKScore(leaderboardIdentifier: "ChineseWeather") //leaderboard id here

scoreReporter.value = Int64(Score) //score variable here (same as above)

var scoreArray: [GKScore] = [scoreReporter]

GKScore.reportScores(scoreArray, withCompletionHandler: {(error : NSError!) -> Void in
if error != nil {
println("error")
}
})

}

}

最佳答案

通过转动这个来解决:

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

进入这个:

func showLeaderboard() {
var vc = self
var gc = GKGameCenterViewController()
var gameCenterDelegate: GKGameCenterControllerDelegate!
// Above text was replaced from gc.gameCenterDelegate = self
vc.presentViewController(gc, animated: true, completion: nil)
}

我不知道为什么,但它奏效了。

关于ios - 显示游戏中心排行榜无法快速工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30123268/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com