[英]ios scheduledTimerWithTimeInterval for amount of time
I want to use scheduledTimerWithTimeInterval to do a periodic task for certain amount of time lets say one hour. 我想使用scheduledTimerWithTimeInterval来执行一段时间的定期任务,比如一小时。 but How do I implement on my code.
但是我如何在我的代码上实现。 Here is my code:
这是我的代码:
timer = [NSTimer scheduledTimerWithTimeInterval: 0.1
target: self
selector: @selector(doSomething:)
userInfo: nil
repeats: YES];
Lets assume for a minute . 让我们假设一分钟。
Here is simple scenario , 这是一个简单的场景,
int remainingCounts;
NSTimer *timer;
timer = [NSTimer scheduledTimerWithTimeInterval:1 target:(self) selector:@selector(countDown) userInfo:nil repeats:YES];
remainingCounts = 60; // int remainingCounts ;...
Method being called for every sec. 每秒调用一次方法。
-(void)countDown {
NSLog(@"%d", remainingCounts);
// Do Your stuff......
if (--remainingCounts == 0) {
//[self dismissViewControllerAnimated:YES completion:nil];
[timer invalidate];
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.