NSTimeIntervalでカウントダウンを試みました。しかし、毎回更新をリリースせずに間隔を変更できるようにしたい。そこで私は自分のウェブサイトからタイムインターバルをインポートしようとしました。私はNSTimeIntervalの数値をNSStringに保存しており、カウントダウンコードに実装するためにNSTimeIntervalに変換したいと考えています...NSStringをNSTimeIntervalに変換する
...それは動作しません。何か案は?
label.text = string;
double timeInterval = [label.text doubleValue];
NSTimeInterval intervalForTimer = timeInterval;
destinationDate = [[NSDate dateWithTimeIntervalSince1970:intervalForTimer] retain];
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateLabel) userInfo:nil repeats:YES];
編集:
- (void)updateLabel {
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
int units = NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *components = [calendar components:units fromDate:[NSDate date] toDate:destinationDate options:0];
[dateLabel setText:[NSString stringWithFormat:@"%d%c %d%c %d%c %d%c %d%c", [components month], 'm', [components day], 'd', [components minute], 'm', [components second], 's']];
}
私の新しいコードは以下のようになります。
NSLog(@"Downloaded file with contents: %@", string);
double timeInterval = [string doubleValue];
label.text = [NSString stringWithFormat:@"%d", (int)timeInterval];
NSTimeInterval intervalForTimer = timeInterval;
destinationDate = [[NSDate dateWithTimeIntervalSince1970:timeInterval] retain];
timer = [NSTimer scheduledTimerWithTimeInterval:intervalForTimer target:self selector:@selector(updateLabel) userInfo:nil repeats:YES];
しかしdateLabelは何もしません...
問題は何ですか?それはokと思われる –
どのように動作していないのですか?文字列の値が正しく入力されていることを確認しましたか(デバッガを表示または見て確認していますか?)ラベルテキストが正しく設定されていることを確認しましたか? –
label.textとは何ですか? – Shmidt