1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
import
UIKit
class
ViewController
:
UIViewController
{
var
timer:
NSTimer
!
override
func
viewDidLoad() {
super
.viewDidLoad()
// 启用计时器,控制每秒执行一次tickDown方法
timer =
.scheduledTimerWithTimeInterval(1,
target:
self
,selector:
Selector
(
"tickDown"
),
userInfo:
nil
ottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.5em!important; margin:0px!important; overflow:visible!important; padding:1px 0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,repeats:
true
)
}
/**
*计时器每秒触发事件
**/
tickDown()
{
print
"tick..."
)
}
didReceiveMemoryWarning() {
.didReceiveMemoryWarning()
}
}
|
2,如果要停止定时器,调用NSTimer的invalidate()方法即可
timer.invalidate() |