scheduledTimerWithTimeInterval使用方法

1、定义NSTimer

NSTimer *lookforTimer;



2、初始化,添加定时器前先移除  

[lookforTimer invalidate];

lookforTimer=nil;


lookforTimer= [NSTimerscheduledTimerWithTimeInterval:2.0ftarget:selfselector:@selector(lookforCard:)userInfo:nilrepeats:YES];


3、停止

[lookforTimer invalidate];

lookforTimer =nil;


封装
#pragma mark - 添加定时器

- (void)addTimer

{

   self.Timer= [NSTimerscheduledTimerWithTimeInterval:1.0target:selfselector:@selector(lookforCard)userInfo:nilrepeats:YES];  

[[NSRunLoop mainRunLoop] addTimer:self.TimerforMode:NSRunLoopCommonModes];

}

#pragma mark - 移除定时器

- (void)removeTimer

{

    [self.Timerinvalidate];

   self.Timer=nil;

}



版权声明:本文为zwl492454828原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。