我想用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];
}
}