我一直在搜索互联网几天到现在。我确实找到了一些有用的信息,但只是想让事情变得完美。Iphone应用风格倒数改进?
我正在尝试写一个倒数计时器应用程序,它只使用第二个应用程序,我现在的代码有点太复杂,可能不在主要道路上。寻找一个能够把它弄直的人。
- (void)updateTimer{
NSDate *currentDate = [NSDate date];
NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:startDate];
NSDate *timerDate = [NSDate dateWithTimeIntervalSince1970:timeInterval];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"s"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0.0]];
NSString *timeString=[dateFormatter stringFromDate:timerDate];
// where the part change time string back to int
NSString *changeToInt = timeString;
int stringInt = [changeToInt integerValue];
// loop for count down numbers
if ((buttValue - stringInt) > 0) {
leftTime = buttValue - stringInt;
[self updateValue];
} else {
leftTime = 0;
[self updateValue];
}
}
2问题的代码,1)我必须通过所有的日期格式得到一个整数? 2)在循环中我使用了两个变量,我希望能拿出一个并使用类似的东西 -
我是这样一个傻瓜,我不明白scheduledTimerWithTimeInterval是如何工作的。如果((buttValue-1)> 0)buttValue = buttValue-1;}如果((buttValue-1)> 0),我现在将代码更改为反向倒计数 。 [self updateValue]; } else { buttValue = 0; [self updateValue]; [timer invalidate]; }' – oursonvie 2012-03-26 09:42:13