毕业论文

当前位置: 毕业论文 > 范文 >

scheduledTimerWithTimeInterval如何使用

时间:2022-09-12 15:45来源:优尔论文
scheduledTimerWithTimeInterval如何使用,定义NSTimer,NSTimer *lookforTimer;初始化,添加定时器前先移除

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;

}

scheduledTimerWithTimeInterval如何使用:http://www.chuibin.com/fanwen/lunwen_99314.html
------分隔线----------------------------
推荐内容