任何人都可以在我可以插入highscoreLabel的地方提供帮助,我不断产生错误,我一直在研究将代码移至viewDidAppear和viewDidLoad。
我只是从头开始,所以如果有人可以帮助,那就太好了。
谢谢。
import UIKit
import SpriteKit
import AVFoundation
import GameKit
class StatsViewController: UIViewController {
var highScoreLabelNode = SKLabelNode()
var highScore = NSInteger()
var highscoreDefault = NSInteger()
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(true)
let highscoreDefault = NSUserDefaults.standardUserDefaults()
let score = highscoreDefault.valueForKey("HighScore")
highScoreLabelNode.fontName = "Helvetica-Bold"
highScoreLabelNode.position = CGPoint(x: 2.48, y: 1.17 )
highScoreLabelNode.fontSize = 30
highScoreLabelNode.alpha = 0.7
highScoreLabelNode.text = "Highscore \(score)"
addChild(highScoreLabelNode) //USE OF UNRESOLVED IDENTIFIER 'ADDCHILD'
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func shouldAutorotate() -> Bool {
return true
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
return UIInterfaceOrientationMask.AllButUpsideDown
} else {
return UIInterfaceOrientationMask.All
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Release any cached data, images, etc that aren't in use.
}
override func prefersStatusBarHidden() -> Bool {
return true
}
}
最佳答案
查看错误,您应该看到问题出在在于addChild不是一个函数,因此将其放在其他函数中将无法解决此问题。您需要在视图控制器的视图上调用正确的函数。
基于以下链接的问题的答案,我相信您需要:
self.view.addSubview(highScoreLabelNode)
How to add child to view controller swift?
关于ios - 使用 Unresolved 标识符“addChild”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33088243/