我试过这个,但什么也没发生.选择器有问题吗?
func timer() {
var timer = NSTimer(timeInterval: 2.0, target: self, selector:Selector("function"), userInfo: nil, repeats: false)
}
func function() {
println("it worked")
}
Run Code Online (Sandbox Code Playgroud)
Chu*_*uck 12
您只是创建计时器,但不将其添加到运行循环中.您需要使用等效的scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:类方法或在运行循环上安排它addTimer:forMode:.
| 归档时间: |
|
| 查看次数: |
4484 次 |
| 最近记录: |