定时器操作NSTimer
2015-08-25 本文已影响139人
Pierre_
NSTimer * timer;
timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(timerStart:) userInfo:nil repeats:YES];
[timer setFireDate:[NSDate distantFuture]]; //定时器暂停
[timer setFireDate:[NSDate distantPast]]; //继续
=========定时器最后的销毁
-(void)dealloc{
if ([timer isValid ])
{
[timer invalidate]; //关闭定时器
timer = nil;
}
}
//取消定时器
[timer invalidate];
}