Quantcast
Channel: shin3tky blog
Viewing all articles
Browse latest Browse all 25

プログレス表示を即時反映する

$
0
0

時間の掛かる処理でプログレス表示をする場合に、n % まで更新しました、という表示が反映されなかったため、次のように対処。


OTProgress は自前の HUD クラス。

NSRunLoop:runUtilDate: にて RunLoop に間を与えることで再描画されました。


[OTProgress showWithStatus:@"ロード中… 0%"];
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];

int total = [items count];
int n = 0;
for (Item *item in items) {

  // 時間の掛かる処理

  if (n % 10 == 0) {
    [OTProgress setStatus:[NSString stringWithFormat:@"ロード中… %d%%",
      (int)(((float)n / (float)total) * 100.0)]];
    [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
  }
  n++;
}

[OTProgress setStatus:@"ロード中… 100%"];
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];

[OTProgress dismiss];


Viewing all articles
Browse latest Browse all 25

Trending Articles