私は今まで数日間インターネットを検索してきました。役立つ情報をいくつか見つけましたが、物事を完璧にしたいだけです。
秒のみを使用するカウントダウン アプリを作成しようとしています。現在のコードは少し複雑すぎて、幹線道路から外れている可能性があります。直していただける方募集中です。
- (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) ループで 2 つの変数を使用しました。