1、全局定义
NSTimer*count_time;
int seconds;
2、启动定时器
seconds = 0;
count_time = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeCount:) userInfo:nil repeats:YES];
- (void)timeCount:(NSTimer*)timer{
seconds++;
}
3、暂停定时器
[count_time setFireDate:[NSDate distantFuture]];
4、继续定时器
[count_time setFireDate:[NSDate distantPast]];
5、销毁定时器(一定要销毁,不然会造成内存泄露)
if(count_time) {
[count_timeinvalidate];
count_time=nil;
}