我创建了一个倒数计时器,它工作得很好..但是当它达到零时,它会继续倒计时..所以它显示-1、-2、-3等。我该如何防止它这样做?
这是我的实现文件中的代码..
@implementation ViewController
-(IBAction)start {
myTicker = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(showActivity) userInfo:nil repeats:YES];
}
-(IBAction)stop {
[myTicker invalidate];
}
-(IBAction)reset {
time.text = @"0";
}
-(void)showActivity {
int currentTime = [time.text intValue];
int newTime = currentTime -1;
time.text = [NSString stringWithFormat:@"%d", newTime];
}
我猜我在某处遗漏了一些代码?