0

私はこのコードで NSTimer を使用しています:

- (IBAction)start:(id)sender {

    MainInt = 0;

    timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countup) userInfo:nil repeats:YES];

}

ミリ秒と分も表示するにはどうすればよいですか?

シンプルでありながら機能する方法は見つかりませんでした。

4

2 に答える 2

1

ミリ秒の場合:

timer = [NSTimer scheduledTimerWithTimeInterval:0.001 target:self selector:@selector(countup)userInfo:nil repeats:YES];

議事録の場合:

timer = [NSTimer scheduledTimerWithTimeInterval:60.0 target:self selector:@selector(countup)userInfo:nil repeats:YES];
于 2012-08-19T13:50:51.340 に答える
0

0.1f timer = [NSTimerscheduledTimerWithTimeInterval:0.1f のように間隔を短くし、カウンターを表示するためにtarget:self selector:@selector(countup)userInfo:nil repeats:YES]; 使用します。NSDateFormatterの例はNSDateFormatterここにあります: timer = [NSTimerscheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countup)userInfo:nil repeats:YES];

NSDateFormatter の仕組みについては、ここでよく説明されています: NSDateFormatter を使用してさまざまな日時形式を処理する方法

タイマーは、ミリ秒を格納する float 変数を更新する必要があります。

サンプル:

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"mm:ss:SSS"];
    NSTimeInterval interval = [startDate timeIntervalSinceNow]*-1;
    NSString *clock = [formatter stringFromDate:[NSDate dateWithTimeInterval:interval sinceDate:startDate]];

しかし、あなたはロイ・シャロンの答えに行くべきです.

于 2012-08-19T13:48:32.387 に答える