-3

リアルタイム データを表示する必要がある場合、UIViewController をオンザフライで更新するにはどうすればよいですか? たとえば、タイムレコーダーをビューに表示したいとします。2 番目の部分は、1 秒ごとに 1 ずつ増加します。UIViewController に、明示的に更新せずにコンテンツを自動的に変更するバックグラウンド プロセスを持たせるには、どのメソッドを呼び出す必要がありますか?

4

2 に答える 2

0

UIViewControllerクロック オブジェクトのみを更新する場合は、全体を更新する必要はありません。

1 秒に 1 回クロックを更新する 1 つの方法は、 を使用することNSTimerです。ドキュメンテーションはこちら

[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateClock:) userInfo:nil repeats:YES];
于 2013-11-14T19:21:05.167 に答える
0

全体を更新する必要はありません。時計を更新するだけで済みます。たとえば、デジタル時計を使用している場合は、次のことができます。

- (void)clockTimerStart{
    //call this in your viewDidLoad method

    //start the clock
    NSTimer *clockTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateClock) userInfo:nil repeats:YES];
}

次に、あなたのupdateClock方法のために

- (void)updateClock{
    //this will be called every second while the clockTimer method is running
    //you could increment the time here. For example, if your incrementing
    //variable was named "increment"

    increment++;
}

次に、夜時計を止めたいときは、次を使用できますclockTimer = nil

于 2013-11-15T04:19:51.127 に答える