iOS基础·OC语法篇

定时器操作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];
}

上一篇下一篇

猜你喜欢

热点阅读