我在里面有一个UILabel
和一个,我在那个里面有一个。View
Stack View
ViewController
GameScene
View
''''''''''''''' <- GameStartViewController
' L '
' ''''''''' ' L = UILabel
' ' V ' ' V = View Frame
' ' ' '
' ' ' '
' ' ' '
' ''''''''' '
' '
'''''''''''''''
我正在尝试更新视图内部的分数标签,但我不断得到
fatal error: unexpectedly found nil while unwrapping an Optional value
即使它已连接,我也无法更改颜色、设置文本等...
代码:
GameScene.swift
var gs: GameStartViewController!
override func didMoveToView(view: SKView) {
physicsWorld.contactDelegate = self
self.backgroundColor = UIColor.feelFreeToColor()
gs.scoreLabel.text = "\(score)" // THIS DOES NOT WORK
}
GameStartViewController.swift
@IBOutlet weak var selfView: SKView!
@IBOutlet weak var scoreLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.feelFreeToColor()
self.initAdMobBanner()
let scene: GameScene = GameScene(size: view.bounds.size)
let skView = selfView
scene.scaleMode = .AspectFill
skView.presentScene(scene)
scoreLabel.layer.addBorder(UIRectEdge.Bottom, color: UIColor.blackColor(), thickness: 3) // THIS WORKS
}
我可以从视图控制器编辑它,但不能在视图框架内。如何从视图框架内访问它?