IOS 定时器
-(void)initTimer{
//时间间隔
NSTimeInterval timeInterval = 1.0 ;
//定时器
NSTimer *showTimer = [NSTimer scheduledTimerWithTimeInterval:timeInterval
target:self
selector:@selector(handleMaxShowTimer:)
userInfo:nil
repeats:NO];
[showTimer fire];
}
//触发事件
-(void)handleMaxShowTimer:(NSTimer *)theTimer{
NSLog(@"initTimer");
}
方式二:
//时间间隔
NSTimeInterval timeInterval = 1.0 ;
//定时器
NSTimer *showTimer = [NSTimer scheduledTimerWithTimeInterval:timeInterval
target:self
selector:@selector(handleTimer:)
userInfo:nil
repeats:NO];
showTimer.fireDate = [NSDate dateWithTimeIntervalSinceNow:timeInterval];
scheduled 会自动执行,不用fire 也可以。fire是立即执行的意思,会忽略firedate这个参数。
上面的程序会在1秒后执行。
浙公网安备 33010602011771号