@property (nonatomic, strong) NSTimer *timer;
添加定时器
self.timer = [NSTimer scheduledTimerWithTimeInterval:999.0 target:self selector:@selector(executeFun) userInfo:nil repeats:YES];//999.0代表要延时的时间,executeFund代表要999秒后需要执行的方法
[[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];//将定时器加入到事件循环
删除定时器
[self.timer invalidate];
self.timer = nil;
IOS初级:NSTimer
最新推荐文章于 2019-04-25 03:07:21 发布