1 つのボタンで時間をキャプチャするタイムスタンプ アプリを作成しようとしています。
ボタンを押すと、現在の時刻が出力されます00:00:00
。ボタンを 2 回押すと、現在の時刻が再度表示されます (例: 00:00:15
)。
次に、2 つのタイムスタンプの時間差 (10 秒) を計算します。
私はobjective-cが初めてで、この小さな問題に何時間も取り組んできました。正しい方向にポインタを持っているといいでしょう。
に問題がありtimeIntervalSinceDate
ます。コードは次のとおりです。
- (IBAction)checkButton:(id)sender {
if (buttonPress) {
self.checkInStamp = [NSDate date];
NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
[timeFormatter setTimeStyle:NSDateFormatterMediumStyle];
checkInTime.text = [timeFormatter stringFromDate:checkInStamp];
buttonPress = false;
}
else {
self.checkOutStamp = [NSDate date];
NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
[timeFormatter setTimeStyle:NSDateFormatterMediumStyle];
checkOutTime.text = [timeFormatter stringFromDate:checkOutStamp];
NSTimeInterval timeDifference = [checkOutStamp timeIntervalSinceDate:checkInStamp];
totalDuration.text = @"%d", timeDifference; //<-This gives "Expression result unused on build"
}
}
助けてくれてありがとう!