我想使用 ScheduledTimerWithTimeInterval 来执行一定时间的定期任务,比如说一小时。但我如何在我的代码上实现。这是我的代码:
timer = [NSTimer scheduledTimerWithTimeInterval: 0.1
target: self
selector: @selector(doSomething:)
userInfo: nil
repeats: YES];
让我们假设一下。
这是简单的场景,
int remainingCounts;
NSTimer *timer;
timer = [NSTimer scheduledTimerWithTimeInterval:1 target:(self) selector:@selector(countDown) userInfo:nil repeats:YES];
remainingCounts = 60; // int remainingCounts ;...
每秒调用一次方法。
-(void)countDown {
NSLog(@"%d", remainingCounts);
// Do Your stuff......
if (--remainingCounts == 0) {
//[self dismissViewControllerAnimated:YES completion:nil];
[timer invalidate];
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)