1、定义NSTimer
NSTimer *lookforTimer;
2、初始化,添加定时器前先移除
[lookforTimer invalidate];
lookforTimer =nil;
lookforTimer = [NSTimerscheduledTimerWithTimeInterval:2。0ftarget:selfselector:@selector(lookforCard:)userInfo:nilrepeats:YES];
3、停止
[lookforTimer invalidate];scheduledTimerWithTimeInterval如何使用
lookforTimer =nil;
封装
#pragma mark - 添加定时器
- (void)addTimer
{
self。Timer = [NSTimer scheduledTimerWithTimeInterval:1。0 target:self selector:@selector(lookforCard) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:self。Timer forMode:NSRunLoopCommonModes];scheduledTimerWithTimeInterval如何使用
}
#pragma mark - 移除定时器
- (void)removeTimer
{
[self。Timer invalidate];
self。Timer = nil;
}