从视图框内编辑UILabel

时间:2016-05-11 06:30:09

标签: ios swift skview

UILabelView内有Stack ViewViewController GameSceneView ''''''''''''''' <- GameStartViewController ' L ' ' ''''''''' ' L = UILabel ' ' V ' ' V = View Frame ' ' ' ' ' ' ' ' ' ' ' ' ' ''''''''' ' ' ' ''''''''''''''' fatal error: unexpectedly found nil while unwrapping an Optional value var gs: GameStartViewController! override func didMoveToView(view: SKView) { physicsWorld.contactDelegate = self self.backgroundColor = UIColor.feelFreeToColor() gs.scoreLabel.text = "\(score)" // THIS DOES NOT WORK }

@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
}

我正在尝试更新标签,这是视图内部的分数,但我一直在

SELECT distinct Year FROM bucketed_table tablesample(bucket 1 out of Y on year);
SELECT distinct Year FROM bucketed_table tablesample(bucket 2 out of Y on year);

即使已连接,我也无法更改颜色,设置文字等...

代码:

GameScene.swift

SELECT count(*) FROM bucketed_table tablesample(bucket 1 out of Y on year);

GameStartViewController.swift

//suppose that bucket 1 stores year X

我可以从视图控制器编辑它,但不能在视图框内。如何从视图框内访问它?

2 个答案:

答案 0 :(得分:0)

如果您尝试gs.scoreLabel.text = "Test content"会发生什么?

您在哪里设置和填写分数变量?

答案 1 :(得分:0)

您在哪里设置对视图中父级的引用(在您的情况下为gs)?.

尝试在ViewController中设置父引用,如下所示:

override func viewDidLoad() {
    super.viewDidLoad()

    self.view.backgroundColor = UIColor.feelFreeToColor()
    self.initAdMobBanner()

    let scene: GameScene = GameScene(size: view.bounds.size)

    // Notice!
    scene.gs = self

    let skView = selfView
    scene.scaleMode = .AspectFill
    skView.presentScene(scene)

    scoreLabel.layer.addBorder(UIRectEdge.Bottom, color: UIColor.blackColor(), thickness: 3) // THIS WORKS
}