我正在使用 xCode 4.3.2,在我的倒计时计时器项目(代码如下所示)中,我想在 30 秒后停止倒计时。如何为我的倒计时设置此限制?请你帮助我好吗?
int countLimit=30; //seconds
NSDate *startDate;
- (void)countDown{
NSDate *currentDate = [NSDate date];
NSTimeInterval timeInterval = -([currentDate timeIntervalSinceDate:startDate]);
NSDate *timerDate = [NSDate dateWithTimeIntervalSince1970:timeInterval];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"HH:mm:ss"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0.0]];
NSString *timeString=[dateFormatter stringFromDate:timerDate];
self.myCounterLabel.text = timeString;
[dateFormatter release];
}
- (void)updateCounter{
self.myCounterLabel.text = @"00:00:00";
startDate = [[NSDate date]retain];
myTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/10.0
target:self
selector:@selector(countDown)
userInfo:nil
repeats:YES];
}