当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - UILabel not being changed, glitches occur - Xcode Swift

问题描述:

In my Swift Xcode project, I am trying to change the text in a UILabel to an integer which is the score.

scoreLabel.text = String(score);

scoreLabel is a UILabel and score is an integer that is casted to a String, and used as the text for scoreLabel. When I enter this line in my project, my application glitches very severely and I don't know why. What is the best way to display a changing score in Xcode? I want to display an integer on the application screen and have it chnage programmatically. Thanks in advance.

网友答案:

Usually this kind of stuff happens when you try to modify the UI from a background thread.

Try this:

NSOperationQueue.mainQueue().addOperationWithBlock { self.scoreLabel.text = "\(score)" }

If that works, then that is your problem. If not... then I have no idea unfortunately.

分享给朋友:
您可能感兴趣的文章:
随机阅读: