iOs*_*bie 1 xcode label selector swift ios8
我有一个计时器,它调用一个选择器.直接从该函数,我想更改标签的文本.
@IBOutlet weak var myLabel: UILabel!
override func viewDidLoad() {
var timer = NSTimer.scheduledTimerWithTimeInterval(0.4, target: self, selector: Selector("update"), userInfo: nil, repeats: true)
}
func update () {
self.myLabel.text = "MyNewText"
}
Run Code Online (Sandbox Code Playgroud)
Xcode告诉我使用"self",但标签仍然没有更新!谢谢你的帮助!
UI更新必须始终在主线程中完成,因此请尝试以下操作:
func update () {
DispatchQueue.main.async {
self.myLabel.text = "MyNewText"
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15789 次 |
| 最近记录: |