定时器的时间单位是秒.
NSTimer *timer
1.运行一次自动停止
timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(function:) userInfo:nil repeats:NO];
这样timer运行一次就会自动停下来的
2.重复运行在方法中停止
timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(function:) userInfo:nil repeats:YES];
就会每三秒运行一次function:
在function:中加入 [timer invalidate];语句可在内部令其停止
NSTimer *timer
1.运行一次自动停止
timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(function:) userInfo:nil repeats:NO];
这样timer运行一次就会自动停下来的
2.重复运行在方法中停止
timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(function:) userInfo:nil repeats:YES];
就会每三秒运行一次function:
在function:中加入 [timer invalidate];语句可在内部令其停止